Skip to content

Remove nullability annotation from MetadataLoadContext.CoreAssembly.#126142

Open
teo-tsirpanis wants to merge 2 commits intodotnet:mainfrom
teo-tsirpanis:mlc-core-assembly-nullability
Open

Remove nullability annotation from MetadataLoadContext.CoreAssembly.#126142
teo-tsirpanis wants to merge 2 commits intodotnet:mainfrom
teo-tsirpanis:mlc-core-assembly-nullability

Conversation

@teo-tsirpanis
Copy link
Contributor

This property will never be null, because failing to resolve the core assembly would throw when creating the MLC. We update the property's nullability annotation, and simplify code flow to make this evident.

Copilot AI review requested due to automatic review settings March 26, 2026 02:54
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 26, 2026
Copy link
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

This PR updates MetadataLoadContext.CoreAssembly to be non-nullable by making core-assembly resolution an up-front, throwing operation, and refactors related initialization to reflect that invariant.

Changes:

  • Change CoreAssembly from Assembly? to Assembly (including the ref assembly).
  • Resolve and store the core assembly during MetadataLoadContext construction via a new LoadCoreAssembly helper.
  • Refactor CoreTypes initialization to accept a resolved RoAssembly directly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/CoreTypes.cs Refactors CoreTypes ctor to take a resolved core RoAssembly and simplifies initialization loop.
src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/MetadataLoadContext.CoreAssembly.cs Replaces TryGetCoreAssembly with LoadCoreAssembly and changes _coreAssembly to non-nullable readonly.
src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/MetadataLoadContext.Apis.cs Loads core assembly up-front in the constructor and updates CoreAssembly property signature to non-nullable.
src/libraries/System.Reflection.MetadataLoadContext/ref/System.Reflection.MetadataLoadContext.cs Updates public API surface for CoreAssembly nullability in the reference assembly.
Comments suppressed due to low confidence (1)

src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/MetadataLoadContext.Apis.cs:248

  • The XML doc comment for CoreAssembly still states that the value may be null and that the core assembly is loaded lazily. With the property now non-nullable and the constructor resolving the core assembly up-front (throwing if it can’t be found), the docs should be updated to match the actual behavior/contract.
        public Assembly CoreAssembly
        {
            get
            {
                if (IsDisposed)

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Reflection 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.

2 participants