Remove nullability annotation from MetadataLoadContext.CoreAssembly.#126142
Remove nullability annotation from MetadataLoadContext.CoreAssembly.#126142jkotas merged 6 commits intodotnet:mainfrom
MetadataLoadContext.CoreAssembly.#126142Conversation
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)
|
Could you please address copilot feedback? |
c07808a to
cde9080
Compare
|
More copilot nits |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/MetadataLoadContext.CoreAssembly.cs:57
- The summaries for GetCoreType/TryGetCoreType still mention scenarios where the “core assembly name wasn’t supplied” or the “core assembly could not be loaded.” With eager core assembly resolution in the constructor and a non-nullable
_coreAssembly, those conditions should no longer occur at call sites. Please update these comments to reflect the current behavior (primarily “type missing in core assembly”).
private readonly RoAssembly _coreAssembly;
/// <summary>
/// Returns a lazily created and cached Type instance corresponding to the indicated core type. This method throws
/// if the core assembly name wasn't supplied, the core assembly could not be loaded for some reason or if the specified
|
/ba-g build analysis is stuck |
…/runtime#126142 Agent-Logs-Url: https://github.com/dotnet/dotnet-api-docs/sessions/0926574b-ab2c-4fc6-a3bc-d6e60b32393e Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
…/runtime#126142 (#12528) * Port MetadataLoadContext.CoreAssembly nullability changes from dotnet/runtime#126142 Agent-Logs-Url: https://github.com/dotnet/dotnet-api-docs/sessions/0926574b-ab2c-4fc6-a3bc-d6e60b32393e Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com> * Update xml/System.Reflection/MetadataLoadContext.xml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update xml/System.Reflection/MetadataLoadContext.xml Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com> Co-authored-by: Jan Kotas <jkotas@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
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.