Skip to content

Commit 70059a9

Browse files
authored
Adjust remarks for Assembly.Load on .NET Core (#9764)
1 parent c069a8c commit 70059a9

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

xml/System.Reflection/Assembly.xml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4011,9 +4011,11 @@ This property is marked obsolete starting in .NET 5, and generates a compile-tim
40114011
<format type="text/markdown"><![CDATA[
40124012

40134013
## Remarks
4014-
<xref:System.IO.FileLoadException> is thrown if `assemblyRef` specifies the full assembly name and the first assembly that matches the simple name has a different version, culture, or public key token. The loader does not continue probing for other assemblies that match the simple name.
40154014

4016-
**.NET Framework only:** See [`<loadFromRemoteSources>`](/dotnet/framework/configure-apps/file-schema/runtime/loadfromremotesources-element) for loading assemblies from remote locations.
4015+
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").
4016+
4017+
> [!NOTE]
4018+
> **.NET Framework only:** For information about loading assemblies from remote locations, see [`<loadFromRemoteSources>`](/dotnet/framework/configure-apps/file-schema/runtime/loadfromremotesources-element).
40174019

40184020
> [!NOTE]
40194021
> **.NET Framework only:** Do not use an <xref:System.Reflection.AssemblyName> with only the <xref:System.Reflection.AssemblyName.CodeBase%2A> property set. The <xref:System.Reflection.AssemblyName.CodeBase%2A> property does not supply any elements of the assembly identity (such as name or version), so loading does not occur according to load-by-identity rules, as you would expect from the <xref:System.Reflection.Assembly.Load%2A> method. Instead, the assembly is loaded using load-from rules. For information about the disadvantages of using the load-from context, see the <xref:System.Reflection.Assembly.LoadFrom%2A?displayProperty=nameWithType> method overload or [Best Practices for Assembly Loading](/dotnet/framework/deployment/best-practices-for-assembly-loading).
@@ -4104,6 +4106,9 @@ Note: In <see href="https://go.microsoft.com/fwlink/?LinkID=247912">.NET for Win
41044106
<format type="text/markdown"><![CDATA[
41054107

41064108
## Remarks
4109+
4110+
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").
4111+
41074112
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 the .NET Framework 4:
41084113

41094114
:::code language="csharp" source="~/snippets/csharp/System.Reflection/Assembly/Load/load11.cs" id="Snippet1":::
@@ -4208,6 +4213,8 @@ To load the correct assembly, it's recommended to call the `Load` method by pass
42084213

42094214
## Remarks
42104215

4216+
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").
4217+
42114218
This method overload always creates a new <xref:System.Reflection.Assembly> object in its own isolated load context.
42124219

42134220
**.NET Framework only:** The trust level of an assembly that is loaded by using this method is the same as the trust level of the calling assembly. To load an assembly from a byte array with the trust level of the application domain, use the <xref:System.Reflection.Assembly.Load%28System.Byte%5B%5D%2CSystem.Byte%5B%5D%2CSystem.Security.SecurityContextSource%29> method overload. For more information about the use of evidence with overloads of the <xref:System.Reflection.Assembly.Load%2A> method that take byte arrays, see the <xref:System.Reflection.Assembly.Load%28System.Byte%5B%5D%2CSystem.Byte%5B%5D%2CSystem.Security.Policy.Evidence%29> method overload.
@@ -4598,6 +4605,11 @@ The assembly is loaded using the supplied evidence. The raw bytes representing t
45984605
<format type="text/markdown"><![CDATA[
45994606

46004607
## Remarks
4608+
4609+
This API is present in .NET Core for compatibility, but it is recommended to use <xref:System.Runtime.Loader.AssemblyLoadContext> overloads in .NET Core 2.0 and later.
4610+
4611+
The assembly is loaded into a new AssemblyLoadContext created for this purpose. For more information on assembly loading, see [Managed assembly loading algorithm](/dotnet/core/dependency-loading/loading-managed#algorithm").
4612+
46014613
Use the <xref:System.Reflection.Assembly.LoadFile%2A> method to load and examine assemblies that have the same identity, but are located in different paths. <xref:System.Reflection.Assembly.LoadFile%2A> does not load files into the load-from context, and does not resolve dependencies using the load path, as the <xref:System.Reflection.Assembly.LoadFrom%2A> method does. <xref:System.Reflection.Assembly.LoadFile%2A> is useful in this limited scenario because <xref:System.Reflection.Assembly.LoadFrom%2A> cannot be used to load assemblies that have the same identities but different paths; it will load only the first such assembly.
46024614

46034615
**.NET Framework only:** See [`<loadFromRemoteSources>`](/dotnet/framework/configure-apps/file-schema/runtime/loadfromremotesources-element) for loading assemblies from remote locations.
@@ -4764,10 +4776,15 @@ See [`<loadFromRemoteSources>`](/dotnet/framework/configure-apps/file-schema/run
47644776
<format type="text/markdown"><![CDATA[
47654777

47664778
## Remarks
4779+
4780+
This API is present in .NET Core for compatibility, but it is recommended to use <xref:System.Runtime.Loader.AssemblyLoadContext> overloads in .NET Core 2.0 and later.
4781+
4782+
The assembly is loaded into the default AssemblyLoadContext. For more information on assembly loading, see [Managed assembly loading algorithm](/dotnet/core/dependency-loading/loading-managed#algorithm").
4783+
47674784
The `assemblyFile` parameter must refer to a URI without escape characters. This method supplies escape characters for all invalid characters in the URI.
47684785

47694786
> [!NOTE]
4770-
> File transfer protocol (FTP) is not supported. If the URI supplied for `assemblyFile` is an FTP address, the assembly is not loaded. No exception is thrown.
4787+
> .NET Framework only: File transfer protocol (FTP) is not supported. If the URI supplied for `assemblyFile` is an FTP address, the assembly is not loaded. No exception is thrown.
47714788

47724789
`assemblyFile` may be absolute or relative to the current directory.
47734790

@@ -5018,7 +5035,7 @@ See [`<loadFromRemoteSources>`](/dotnet/framework/configure-apps/file-schema/run
50185035

50195036
## Remarks
50205037

5021-
In .NET Core and .NET 5+, this method throws <xref:System.NotSupportedException> when called. Use <xref:System.Reflection.Assembly.LoadFrom%28System.String%29> instead.
5038+
This API is not supported in .NET Core/.NET 5+. This method throws <xref:System.NotSupportedException> when called. Use <xref:System.Reflection.Assembly.LoadFrom%28System.String%29> instead.
50225039

50235040
The `assemblyFile` parameter must refer to a URI without escape characters. This method supplies escape characters for all invalid characters in the URI.
50245041

0 commit comments

Comments
 (0)