Skip to content

Add MetadataLoadContext.GetLoadContext(Assembly).#126926

Merged
jkotas merged 1 commit intodotnet:mainfrom
teo-tsirpanis:mlc-get-load-context
Apr 15, 2026
Merged

Add MetadataLoadContext.GetLoadContext(Assembly).#126926
jkotas merged 1 commit intodotnet:mainfrom
teo-tsirpanis:mlc-get-load-context

Conversation

@teo-tsirpanis
Copy link
Copy Markdown
Contributor

Fixes #98756

Copilot AI review requested due to automatic review settings April 15, 2026 00:08
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Apr 15, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a public API to retrieve the MetadataLoadContext associated with an Assembly instance, enabling callers to map reflected Assembly objects back to their originating MetadataLoadContext (per #98756).

Changes:

  • Introduces MetadataLoadContext.GetLoadContext(Assembly) returning the associated context (or null when not applicable).
  • Adds unit coverage validating the method returns the originating context for MLC-loaded assemblies and null for runtime-loaded assemblies.
  • Updates the ref surface area to include the new API (but currently with an incorrect nullability signature).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/MetadataLoadContext.Apis.cs Implements MetadataLoadContext.GetLoadContext(Assembly) using RoAssembly.Loader.
src/libraries/System.Reflection.MetadataLoadContext/ref/System.Reflection.MetadataLoadContext.cs Adds the API to the reference assembly (needs nullability fix to match implementation).
src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Assembly/AssemblyTests.cs Adds tests asserting correct context retrieval and null for non-MLC assemblies.

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Apr 15, 2026

/ba-g DeadLetter

@jkotas jkotas merged commit ab9a190 into dotnet:main Apr 15, 2026
93 of 96 checks passed
@teo-tsirpanis teo-tsirpanis deleted the mlc-get-load-context branch April 15, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Reflection.Metadata community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: MetadataLoadContext.GetLoadContext(Assembly)

3 participants