Skip to content

Commit 6b70ef7

Browse files
Add documentation to the various reflection apis which directly interact with CurrentContextualReflectionContext (#11687)
1 parent b6b66b5 commit 6b70ef7

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

xml/System.Reflection.Emit/AssemblyBuilder.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ The following code example shows how to define and use a dynamic assembly. The e
442442
<param name="access">The access rights of the assembly.</param>
443443
<summary>Defines a dynamic assembly that has the specified name and access rights.</summary>
444444
<returns>An object that represents the new assembly.</returns>
445-
<remarks>To be added.</remarks>
445+
<remarks>.NET 6+ only: If the <see cref="P:System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext" /> property is null, then the assembly is created in the <see cref="T:System.Runtime.Loader.AssemblyLoadContext" /> of the function that calls DefineDynamicAssembly. Otherwise, it's created with the <see cref="T:System.Runtime.Loader.AssemblyLoadContext" /> specified in <see cref="P:System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext" />.</remarks>
446446
</Docs>
447447
</Member>
448448
<Member MemberName="DefineDynamicAssembly">
@@ -505,9 +505,9 @@ The following code example shows how to define and use a dynamic assembly. The e
505505
<param name="name">The name of the assembly.</param>
506506
<param name="access">The access rights of the assembly.</param>
507507
<param name="assemblyAttributes">A collection that contains the attributes of the assembly.</param>
508-
<summary>Defines a new assembly that has the specified name, access rights, and attributes.</summary>
508+
<summary>Defines a dynamic assembly that has the specified name, access rights, and attributes.</summary>
509509
<returns>An object that represents the new assembly.</returns>
510-
<remarks>To be added.</remarks>
510+
<remarks>.NET 6+ only: If the <see cref="P:System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext" /> property is null, then the assembly is created in the <see cref="T:System.Runtime.Loader.AssemblyLoadContext" /> of the function that calls DefineDynamicAssembly. Otherwise, it's created with the <see cref="T:System.Runtime.Loader.AssemblyLoadContext" /> specified in <see cref="P:System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext" />.</remarks>
511511
</Docs>
512512
</Member>
513513
<MemberGroup MemberName="DefineDynamicModule">

xml/System.Reflection/Assembly.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,6 +3241,8 @@ Note: In <see href="https://go.microsoft.com/fwlink/?LinkID=247912">.NET for Win
32413241
## Remarks
32423242
This method only searches the current assembly instance. The `name` parameter includes the namespace but not the assembly. To search other assemblies for a type, use the <xref:System.Type.GetType%28System.String%29?displayProperty=nameWithType> method overload, which can optionally include an assembly display name as part of the type name.
32433243

3244+
In .NET Core/.NET 5+, if there are assembly-qualified generic type parameters in the type name string, those assembly references will be loaded by the <xref:System.Runtime.Loader.AssemblyLoadContext> of the method that called Assembly.GetType, or by the <xref:System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext%2A?displayProperty=nameWithType> context if it's set.
3245+
32443246
> [!NOTE]
32453247
> If the type has been forwarded to another assembly, it is still returned by this method. For information on type forwarding, see [Type Forwarding in the Common Language Runtime](/dotnet/standard/assembly/type-forwarding).
32463248

@@ -3345,6 +3347,8 @@ Note: In <see href="https://go.microsoft.com/fwlink/?LinkID=247912">.NET for Win
33453347
## Remarks
33463348
This method only searches the current assembly instance. The `name` parameter includes the namespace but not the assembly. To search other assemblies for a type, use the <xref:System.Type.GetType%28System.String%29?displayProperty=nameWithType> method overload, which can optionally include an assembly display name as part of the type name.
33473349

3350+
In .NET Core/.NET 5+, if there are assembly-qualified generic type parameters in the type name string, those assembly references will be loaded by the <xref:System.Runtime.Loader.AssemblyLoadContext> of the method that called Assembly.GetType, or by the <xref:System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext%2A?displayProperty=nameWithType> context if it's set.
3351+
33483352
> [!NOTE]
33493353
> If the type has been forwarded to another assembly, it is still returned by this method. For information on type forwarding, see [Type Forwarding in the Common Language Runtime](/dotnet/standard/assembly/type-forwarding).
33503354

@@ -3450,6 +3454,8 @@ Note: In <see href="https://go.microsoft.com/fwlink/?LinkID=247912">.NET for Win
34503454
## Remarks
34513455
This method only searches the current assembly instance. The `name` parameter includes the namespace but not the assembly. To search other assemblies for a type, use the <xref:System.Type.GetType%28System.String%29?displayProperty=nameWithType> method overload, which can optionally include an assembly display name as part of the type name.
34523456

3457+
In .NET Core/.NET 5+, if there are assembly-qualified generic type parameters in the type name string, those assembly references will be loaded by the <xref:System.Runtime.Loader.AssemblyLoadContext> of the method that called Assembly.GetType, or by the <xref:System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext%2A?displayProperty=nameWithType> context if it's set.
3458+
34533459
> [!NOTE]
34543460
> If the type has been forwarded to another assembly, it is still returned by this method. For information on type forwarding, see [Type Forwarding in the Common Language Runtime](/dotnet/standard/assembly/type-forwarding).
34553461

@@ -4097,7 +4103,7 @@ This property is marked obsolete starting in .NET 5, and generates a compile-tim
40974103

40984104
## Remarks
40994105

4100-
In .NET Core/.NET 5+, the target assembly will be loaded into the current <xref:System.Runtime.Loader.AssemblyLoadContext>. For more information on assembly loading, see [Managed assembly loading algorithm](/dotnet/core/dependency-loading/loading-managed#algorithm").
4106+
In .NET Core/.NET 5+, the target assembly will be loaded into the current <xref:System.Runtime.Loader.AssemblyLoadContext> or into the <xref:System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext%2A?displayProperty=nameWithType> context if it's set. For more information on assembly loading, see [Managed assembly loading algorithm](/dotnet/core/dependency-loading/loading-managed#algorithm).
41014107

41024108
> [!NOTE]
41034109
> **.NET Framework only:** For information about loading assemblies from remote locations, see [`<loadFromRemoteSources>`](/dotnet/framework/configure-apps/file-schema/runtime/loadfromremotesources-element).
@@ -4191,7 +4197,7 @@ Note: In <see href="https://go.microsoft.com/fwlink/?LinkID=247912">.NET for Win
41914197

41924198
## Remarks
41934199

4194-
In .NET Core/5+, the target assembly is loaded into the current <xref:System.Runtime.Loader.AssemblyLoadContext>. For more information on assembly loading, see [Managed assembly loading algorithm](/dotnet/core/dependency-loading/loading-managed#algorithm").
4200+
In .NET Core/.NET 5+, the target assembly will be loaded into the current <xref:System.Runtime.Loader.AssemblyLoadContext> or into the <xref:System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext%2A?displayProperty=nameWithType> context if it's set. For more information on assembly loading, see [Managed assembly loading algorithm](/dotnet/core/dependency-loading/loading-managed#algorithm).
41954201

41964202
To load the correct assembly, it's recommended to call the `Load` method by passing the long form of the assembly name. The long form of an assembly name consists of its simple name (such as "System" for the System.dll assembly) along with its version, culture, public key token, and optionally its processor architecture. It corresponds to the assembly's <xref:System.Reflection.Assembly.FullName%2A> property. The following example illustrates the use of a long name to load the System.dll assembly for .NET Framework 4:
41974203

@@ -5571,6 +5577,8 @@ The assembly is loaded into the default AssemblyLoadContext. For more informatio
55715577

55725578
Applications that load assemblies with this method will be affected by upgrades of those assemblies. Therefore, do not use this method; redesign the application to use the <xref:System.Reflection.Assembly.Load%28System.String%29> method overload or the <xref:System.Reflection.Assembly.LoadFrom%28System.String%29> method overload.
55735579

5580+
In .NET Core/5+, the target assembly is loaded into the current <xref:System.Runtime.Loader.AssemblyLoadContext> or the <xref:System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext%2A?displayProperty=nameWithType> if it's set.
5581+
55745582
This method first calls <xref:System.Reflection.Assembly.Load%2A>. If the assembly is not found, this method returns the assembly from the global assembly cache that has the same simple name, and the highest version number.
55755583

55765584
]]></format>

xml/System/Activator.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@ Note: In <see href="https://go.microsoft.com/fwlink/?LinkID=247912">.NET for Win
574574
575575
For more information on how the common language runtime identifies and loads assemblies, see [How the Runtime Locates Assemblies](/dotnet/framework/deployment/how-the-runtime-locates-assemblies). For information on using the application configuration file to define assembly locations, see [Specifying an Assembly's Location](/dotnet/framework/configure-apps/specify-assembly-location). If `assemblyName` is found, it is loaded in the default context.
576576
577+
In .NET Core 3.0 and later versions, assembly loads triggered by this API are affected by the current value of <xref:System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext%2A?displayProperty=nameWithType>.
578+
577579
> [!NOTE]
578580
> This method can be used to create nonpublic types if the caller has been granted <xref:System.Security.Permissions.ReflectionPermission> with the <xref:System.Security.Permissions.ReflectionPermissionFlag.RestrictedMemberAccess?displayProperty=nameWithType> flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later.
579581
@@ -1018,6 +1020,8 @@ Note: In <see href="https://go.microsoft.com/fwlink/?LinkID=247912">.NET for Win
10181020
## Remarks
10191021
Use <xref:System.Runtime.Remoting.ObjectHandle.Unwrap%2A?displayProperty=nameWithType> to unwrap the return value.
10201022
1023+
In .NET Core 3.0 and later versions, assembly loads triggered by this API are affected by the current value of <xref:System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext%2A?displayProperty=nameWithType>.
1024+
10211025
> [!NOTE]
10221026
> This method can be used to create nonpublic types if the caller has been granted <xref:System.Security.Permissions.ReflectionPermission> with the <xref:System.Security.Permissions.ReflectionPermissionFlag.RestrictedMemberAccess?displayProperty=nameWithType> flag and if the grant set of the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later.
10231027
@@ -1493,6 +1497,8 @@ An error occurred when attempting remote activation in a target specified in <pa
14931497
## Remarks
14941498
Use <xref:System.Runtime.Remoting.ObjectHandle.Unwrap%2A?displayProperty=nameWithType> to unwrap the return value.
14951499
1500+
In .NET Core 3.0 and later versions, assembly loads triggered by this API are affected by the current value of <xref:System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext%2A?displayProperty=nameWithType>.
1501+
14961502
> [!NOTE]
14971503
> This method can be used to create nonpublic types and members if the caller has been granted <xref:System.Security.Permissions.ReflectionPermission> with the <xref:System.Security.Permissions.ReflectionPermissionFlag.RestrictedMemberAccess?displayProperty=nameWithType> flag and if the grant set of the assembly that contains the nonpublic types and members is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later.
14981504

0 commit comments

Comments
 (0)