Open IS4Code opened 9 months ago
Tagging subscribers to this area: @vitek-karas, @agocke, @vsadov See info in area-owners.md if you want to be subscribed.
Author: | IS4Code |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-AssemblyLoader-coreclr`, `untriaged` |
Milestone: | - |
Tagging subscribers to this area: @dotnet/area-system-reflection See info in area-owners.md if you want to be subscribed.
Author: | IS4Code |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-System.Reflection`, `area-AssemblyLoader-coreclr`, `untriaged` |
Milestone: | - |
@steveharter This proposal looks good to me. Mark is as api-ready-to-review?
Background and motivation
Unlike
AssemblyLoadContext
, the similarly namedMetadataLoadContext
does not have theGetLoadContext
method that allows retrieving the original load context from its correspondingAssembly
instance. This is inconvenient in situations such as when callingassembly.GetReferencedAssemblies()
and attempting to resolve theAssemblyName
instances.The relevant property is already there, just internal and thus inaccessible.
API Proposal
API Usage
Alternative Designs
Another option, with arguably greater impact but also requirements, would be to make the
Assembly
class expose its loader through a public property, probably as an interface which bothAssemblyLoadContext
andMetadataLoadContext
would implement. This would work with any potential new load context type, but requires modifyingAssembly
and thus would not work easily with older platforms, unlike just modifyingMetadataLoadContext
which is released as a package. It could however remain a possibility even with this API added.Risks
By accessing the
MetadataLoadContext
of anAssembly
, code may load any arbitrary assemblies into the context, but the relatedAssemblyLoadContext
already provides this functionality where it may be more dangerous than here, and theLoader
property is accessible by reflection anyway.