Skip to content

AssemblyLoadContext: Consider adding AssemblyLoadContext.Current API #7642

Closed
@gokarnm

Description

@gokarnm

Right now the AssemblyLoadContext class exposes a Default static property that returns the default load context (AppPathAssemblyLoadContext). Consider adding an AssemblyLoadContext.Current static property that returns the current AssemblyLoadContext from which the calling type's assembly is resolved. Here are some data points to support this API.

  • ALC is poorly documented and generally not very well understood. Usually third party library/framework developers don't need to deal with this class unless they are loading dynamic assemblies or loading assemblies outside of the TPA list. It's easy to incorrectly use AssemblyLoadContext.Default to load assemblies instead of using the current ALC, as AssemblyLoadContext.Default is discoverable and the developer may not know the implications of loading into default vs. current ALC. A developer may not be even aware of 'current ALC' as a concept.
  • Bugs related to loading in default ALC instead of current ALC may surface only when someone loads the affected library in a custom ALC and subsequently sees assembly resolution errors. This may not be a popular use case, may not have been envisioned and tested by the library developer.
  • By providing a new AssemblyLoadContext.Current API with appropriate documentation, it would be clearer to the library developer and possibly force to think about using default or current ALC as per their use case and intended behavior.

As an example, here is an issue in MVC due to use of incorrect ALC for loading - aspnet/Mvc#5960 .

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions