-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Remove nullability annotation from MetadataLoadContext.CoreAssembly.
#126142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,7 +116,8 @@ public MetadataLoadContext(MetadataAssemblyResolver resolver, string? coreAssemb | |
| } | ||
|
|
||
| // Resolve the core assembly now | ||
| _coreTypes = new CoreTypes(this, coreAssemblyName); | ||
| _coreAssembly = LoadCoreAssembly(coreAssemblyName); | ||
| _coreTypes = new CoreTypes(_coreAssembly); | ||
| } | ||
|
teo-tsirpanis marked this conversation as resolved.
|
||
|
|
||
| /// <summary> | ||
|
|
@@ -205,8 +206,7 @@ public Assembly LoadFromAssemblyName(AssemblyName assemblyName) | |
| /// The core assembly is treated differently than other assemblies because references to these well-known types do | ||
| /// not include the assembly reference, unlike normal types. | ||
| /// | ||
| /// Typically, this assembly is named "mscorlib", or "netstandard". If the core assembly cannot be found, the value will be | ||
| /// null and many other reflection methods, including those that parse method signatures, will throw. | ||
| /// Typically, this assembly is named "System.Runtime", "mscorlib", or "netstandard". | ||
| /// | ||
| /// The CoreAssembly is determined by passing the coreAssemblyName parameter passed to the MetadataAssemblyResolver constructor | ||
| /// to the MetadataAssemblyResolver's Resolve method. | ||
|
Comment on lines
211
to
212
|
||
|
|
@@ -220,13 +220,6 @@ public Assembly LoadFromAssemblyName(AssemblyName assemblyName) | |
| /// such as DllImportAttribute. However, it can serve if you have no interest in those attributes. The CustomAttributes api | ||
| /// will skip those attributes if the core assembly does not include the necessary types. | ||
| /// | ||
| /// The CoreAssembly is not loaded until necessary. These APIs do not trigger the search for the core assembly: | ||
| /// MetadataLoadContext.LoadFromStream(), LoadFromAssemblyPath(), LoadFromByteArray() | ||
| /// Assembly.GetName(), Assembly.FullName, Assembly.GetReferencedAssemblies() | ||
| /// Assembly.GetTypes(), Assembly.DefinedTypes, Assembly.GetExportedTypes(), Assembly.GetForwardedTypes() | ||
| /// Assembly.GetType(string, bool, bool) | ||
| /// Type.Name, Type.FullName, Type.AssemblyQualifiedName | ||
| /// | ||
| /// If a core assembly cannot be found or if the core assembly is missing types, this will affect the behavior of the MetadataLoadContext as follows: | ||
| /// | ||
|
Comment on lines
223
to
224
|
||
| /// - Apis that need to parse signatures or typespecs and return the results as Types will throw. For example, | ||
|
|
@@ -240,7 +233,7 @@ public Assembly LoadFromAssemblyName(AssemblyName assemblyName) | |
| /// type, the necessary constructor or any of the parameter types of the constructor, the MetadataLoadContext will not throw. It will omit the pseudo-custom | ||
| /// attribute from the list of returned attributes. | ||
| /// </summary> | ||
| public Assembly? CoreAssembly | ||
| public Assembly CoreAssembly | ||
| { | ||
| get | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,21 +11,25 @@ public sealed partial class MetadataLoadContext | |
| { | ||
| private static readonly string[] s_CoreNames = { "mscorlib", "System.Runtime", "netstandard" }; | ||
|
|
||
| // Cache loaded coreAssembly and core types. | ||
| internal RoAssembly? TryGetCoreAssembly(string? coreAssemblyName, out Exception? e) | ||
| internal RoAssembly LoadCoreAssembly(string? coreAssemblyName) | ||
| { | ||
| Debug.Assert(_coreAssembly == null); | ||
| RoAssembly? coreAssembly; | ||
|
Comment on lines
+14
to
+16
|
||
| Exception? e; | ||
| if (coreAssemblyName == null) | ||
| { | ||
| _coreAssembly = TryGetDefaultCoreAssembly(out e); | ||
| coreAssembly = TryGetDefaultCoreAssembly(out e); | ||
| } | ||
| else | ||
| { | ||
| RoAssemblyName roAssemblyName = new AssemblyName(coreAssemblyName).ToRoAssemblyName(); | ||
| _coreAssembly = TryResolveAssembly(roAssemblyName, out e); | ||
| coreAssembly = TryResolveAssembly(roAssemblyName, out e); | ||
| } | ||
|
|
||
| return _coreAssembly; | ||
| if (coreAssembly == null) | ||
| { | ||
| throw e!; | ||
| } | ||
| return coreAssembly; | ||
| } | ||
|
|
||
| private RoAssembly? TryGetDefaultCoreAssembly(out Exception? e) | ||
|
|
@@ -47,7 +51,7 @@ public sealed partial class MetadataLoadContext | |
| return null; | ||
| } | ||
|
|
||
| private RoAssembly? _coreAssembly; | ||
| private readonly RoAssembly _coreAssembly; | ||
|
|
||
| /// <summary> | ||
| /// Returns a lazily created and cached Type instance corresponding to the indicated core type. This method throws | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.