Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Single file unfriendly APIs #38405

Closed
MichalStrehovsky opened this issue Jun 25, 2020 · 8 comments
Closed

Document Single file unfriendly APIs #38405

MichalStrehovsky opened this issue Jun 25, 2020 · 8 comments

Comments

@MichalStrehovsky
Copy link
Member

MichalStrehovsky commented Jun 25, 2020

This is a running list of APIs that might be problematic for single file and we'll need to tag in some way. Until we have such mechanism here they are:

  • Assembly.Location
  • Assembly.CodeBase
  • Assembly.EscapedCodeBase
  • AssemblyName.CodeBase
  • AssemblyName.EscapedCodeBase
  • AssemblyDependencyResolver
  • Assembly.GetFile
  • Assembly.GetFiles
  • Marshal.GetHINSTANCE
  • Module.FullyQualifiedName

Assembly load APIs that might be problematic if people choose them instead of Assembly.Load by accident:

  • AssemblyLoadContext.LoadFromAssemblyPath
  • Assembly.LoadFile
  • Assembly.LoadFrom
@ghost
Copy link

ghost commented Jun 25, 2020

Tagging subscribers to this area: @swaroop-sridhar
Notify danmosemsft if you want to be subscribed.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Jun 25, 2020
@swaroop-sridhar swaroop-sridhar removed the untriaged New issue has not been triaged by the area owner label Jun 26, 2020
@swaroop-sridhar swaroop-sridhar modified the milestones: 5.0.0, 6.0.0 Jun 26, 2020
@swaroop-sridhar swaroop-sridhar changed the title Single file unfriendly APIs Document Single file unfriendly APIs Jun 26, 2020
@swaroop-sridhar
Copy link
Contributor

We should clearly document these APIs in ms-docs in .net 5.
Linker analysis is targetted for .net6.

@marek-safar
Copy link
Contributor

@swaroop-sridhar are there any tests for the behaviour difference for single-exe for these APIs? I'm asking as we'd like to re-use that for similar scenarios.

@swaroop-sridhar
Copy link
Contributor

@marek-safar we don't have API tests yet. I'm working on a change to add the following tests:

For .netcoreapp3.x single-file apps the APIs will return the actual location of assemblies in the extraction location.
For .net5 single-file apps, the behavior of the above APIs will be the same as assemblies loaded from a byte stream.

  • AppContext.BaseDirectory
    • The single-file app directory for PublishSingleFile=true apps.
    • The extraction directory for PublishSingleFile=true IncludeAllContentInSingleFile=true apps (netcoreapp3.x compatibility mode).
  • Assembly.Location: empty string
  • Assembly.CodeBase, Assembly.EscapedCodeBase, AssemblyName.CodeBase AssemblyName.EscapedCodeBase: empty string
  • Assembly.GetFile: null
  • Assembly.GetFiles: empty array
  • Marshal.GetHINSTANCE: -1

Apart from these, AssemblyLoadContext.LoadFromAssemblyPath and Assembly.LoadFile will only work on actual files.
So, we can subsequently add a test to make sure they are not loaded from the bundle.

Once I have a PR, I'll tag this issue.

@agocke
Copy link
Member

agocke commented Jul 27, 2020

@LakshanF This would be good to put in the docs for PublishSingleFile

@vitek-karas
Copy link
Member

Based on discussion in #40103 and #40087 I suggest to modify the behavior as:

  • AppContext.BaseDirectory
    • The single-file app directory for PublishSingleFile=true apps. [Done]
    • The extraction directory for PublishSingleFile=true IncludeAllContentInSingleFile=true apps (netcoreapp3.x compatibility mode). [Needs verification]
  • Assembly.Location: empty string [Done]
  • Assembly.CodeBase, Assembly.EscapedCodeBase, AssemblyName.CodeBase AssemblyName.EscapedCodeBase: throw PlatformNotSupportedException. Assembly.CodeBase and Assembly.EscapedCodeBase are obsolete in .NET 5. We should discsuss obsoleting AssemblyName.CodeBase and AssemblyName.EscapedCodeBase as well.
  • Module.FullyQualifiedName: <Unknown> string (just like it does in no-single-file for memory-loaded assemblies)
  • Assembly.GetFile: will throw IOException - just like it does in non-single-file for memory-loaded assemblies
  • Assembly.GetFiles: will throw IOException - just like it does in non-single-file for memory-loaded assemblies
  • Marshal.GetHINSTANCE: -1

@MichalStrehovsky
Copy link
Member Author

We should also add "things that p/invoke into [lib]coreclr[.so|.dll|.dylib]", based on #41859.

@tlakollo
Copy link
Contributor

Closing since dotnet/docs#20761 was merged

@ghost ghost locked as resolved and limited conversation to collaborators Apr 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants