Remove nullability annotation from MetadataLoadContext.CoreAssembly.#126142
Open
teo-tsirpanis wants to merge 2 commits intodotnet:mainfrom
Open
Remove nullability annotation from MetadataLoadContext.CoreAssembly.#126142teo-tsirpanis wants to merge 2 commits intodotnet:mainfrom
MetadataLoadContext.CoreAssembly.#126142teo-tsirpanis wants to merge 2 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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
CoreAssemblyfromAssembly?toAssembly(including the ref assembly). - Resolve and store the core assembly during
MetadataLoadContextconstruction via a newLoadCoreAssemblyhelper. - Refactor
CoreTypesinitialization to accept a resolvedRoAssemblydirectly.
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
CoreAssemblystill 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)
...System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/CoreTypes.cs
Outdated
Show resolved
Hide resolved
...tem.Reflection.MetadataLoadContext/src/System/Reflection/MetadataLoadContext.CoreAssembly.cs
Show resolved
Hide resolved
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-reflection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.