Skip to content

Commit 0c25088

Browse files
CopilotjkotasCopilotgewarren
authored
Port MetadataLoadContext.CoreAssembly nullability changes from dotnet/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>
1 parent a951aec commit 0c25088

File tree

1 file changed

+5
-39
lines changed

1 file changed

+5
-39
lines changed

xml/System.Reflection/MetadataLoadContext.xml

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ For more information and examples, see [How to: Inspect assembly contents using
8383
</Docs>
8484
</Member>
8585
<Member MemberName="CoreAssembly">
86-
<MemberSignature Language="C#" Value="public System.Reflection.Assembly? CoreAssembly { get; }" />
86+
<MemberSignature Language="C#" Value="public System.Reflection.Assembly CoreAssembly { get; }" />
8787
<MemberSignature Language="ILAsm" Value=".property instance class System.Reflection.Assembly CoreAssembly" />
8888
<MemberSignature Language="DocId" Value="P:System.Reflection.MetadataLoadContext.CoreAssembly" />
8989
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property CoreAssembly As Assembly" />
@@ -94,12 +94,6 @@ For more information and examples, see [How to: Inspect assembly contents using
9494
<AssemblyName>System.Reflection.MetadataLoadContext</AssemblyName>
9595
<AssemblyVersion>11.0.0.0</AssemblyVersion>
9696
</AssemblyInfo>
97-
<Attributes>
98-
<Attribute FrameworkAlternate="net-10.0-pp;net-11.0-pp">
99-
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
100-
<AttributeName Language="F#">[&lt;System.Runtime.CompilerServices.Nullable(2)&gt;]</AttributeName>
101-
</Attribute>
102-
</Attributes>
10397
<ReturnValue>
10498
<ReturnType>System.Reflection.Assembly</ReturnType>
10599
</ReturnValue>
@@ -113,46 +107,18 @@ For more information and examples, see [How to: Inspect assembly contents using
113107
114108
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.
115109
116-
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 an exception.
110+
Typically, this assembly is named "System.Runtime", "mscorlib", or "netstandard".
117111
118-
The `CoreAssembly` is determined by passing the `coreAssemblyName` parameter passed to the <xref:System.Reflection.MetadataAssemblyResolver> constructor
119-
to the <xref:System.Reflection.MetadataAssemblyResolver.Resolve*?displayProperty=nameWithType> method.
112+
The `CoreAssembly` is determined by passing the `coreAssemblyName` parameter to the <xref:System.Reflection.MetadataLoadContext> constructor,
113+
which in turn passes it to the <xref:System.Reflection.MetadataAssemblyResolver.Resolve*?displayProperty=nameWithType> method.
120114
121115
If no `coreAssemblyName` argument was specified in the constructor of <xref:System.Reflection.MetadataLoadContext>, then default values are used, including "mscorlib", "System.Runtime" and "netstandard".
122116
123117
The designated core assembly does not need to contain the core types directly. It can type forward them to other assemblies. Thus, it is perfectly permissible to use the mscorlib facade as the designated core assembly.
124118
125119
Note that <xref:System.Runtime> is not an ideal core assembly because it excludes some of the interop-related pseudo-custom attribute types such as <xref:System.Runtime.InteropServices.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.
126120
127-
The core assembly is not loaded until necessary. The following APIs do not trigger the search for the core assembly:
128-
129-
* <xref:System.Reflection.MetadataLoadContext.LoadFromStream*?displayProperty=nameWithType>
130-
* <xref:System.Reflection.MetadataLoadContext.LoadFromAssemblyPath*?displayProperty=nameWithType>
131-
* <xref:System.Reflection.MetadataLoadContext.LoadFromByteArray*?displayProperty=nameWithType>
132-
* <xref:System.Reflection.Assembly.GetName*?displayProperty=nameWithType>
133-
* <xref:System.Reflection.Assembly.FullName?displayProperty=nameWithType>
134-
* <xref:System.Reflection.Assembly.GetReferencedAssemblies*?displayProperty=nameWithType>
135-
* <xref:System.Reflection.Assembly.GetTypes*?displayProperty=nameWithType>
136-
* <xref:System.Reflection.Assembly.DefinedTypes?displayProperty=nameWithType>
137-
* <xref:System.Reflection.Assembly.GetExportedTypes*?displayProperty=nameWithType>
138-
* <xref:System.Reflection.Assembly.GetForwardedTypes*?displayProperty=nameWithType>
139-
* <xref:System.Reflection.Assembly.GetType(System.String,System.Boolean,System.Boolean)?displayProperty=nameWithType>
140-
* <xref:System.Type.Name?displayProperty=nameWithType>
141-
* <xref:System.Type.FullName?displayProperty=nameWithType>
142-
* <xref:System.Type.AssemblyQualifiedName?displayProperty=nameWithType>
143-
144-
If a core assembly cannot be found or if the core assembly is missing types, this will affect the behavior of the <xref:System.Reflection.MetadataLoadContext> as follows:
145-
146-
* APIs that need to parse signatures or typespecs and return the results as <xref:System.Type> objects will throw an exception. For example:
147-
148-
* <xref:System.Reflection.MethodInfo.ReturnType?displayProperty=nameWithType>
149-
* <xref:System.Reflection.MethodBase.GetParameters*?displayProperty=nameWithType>
150-
* <xref:System.Type.BaseType?displayProperty=nameWithType>
151-
* <xref:System.Type.GetInterfaces*?displayProperty=nameWithType>
152-
153-
* APIs that need to compare types to well-known core types will not throw an exception, and the comparison will evaluate to `false`. For example, if you do not specify a core assembly, <xref:System.Type.IsPrimitive> will return `false` for everything, even types named <xref:System.Int32>. Similarly, <xref:System.Type.GetTypeCode*?displayProperty=nameWithType> will return <xref:System.TypeCode.Object> for everything.
154-
155-
* If a metadata entity sets flags that surface as a pseudo-custom attribute, and the core assembly does not contain the pseudo-custom attribute type, the necessary constructor or any of the parameter types of the constructor, the <xref:System.Reflection.MetadataLoadContext> will not throw. It will omit the pseudo-custom attribute from the list of returned attributes.
121+
If a core assembly cannot be found, the constructor of <xref:System.Reflection.MetadataLoadContext> throws an exception.
156122
]]></format>
157123
</remarks>
158124
</Docs>

0 commit comments

Comments
 (0)