From f8b4745ae754774ebf2a802ef1fd1f2bf6dbd024 Mon Sep 17 00:00:00 2001 From: Rui Date: Mon, 3 Dec 2018 15:33:51 -0500 Subject: [PATCH] Clarify use of LoadFromAssemblyName method (#21256) --- Documentation/design-docs/assemblyloadcontext.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Documentation/design-docs/assemblyloadcontext.md b/Documentation/design-docs/assemblyloadcontext.md index b8885100..cf6c92c 100644 --- a/Documentation/design-docs/assemblyloadcontext.md +++ b/Documentation/design-docs/assemblyloadcontext.md @@ -68,7 +68,13 @@ This method should be overriden in a *Custom LoadContext* if the intent is to ov ### LoadFromAssemblyName -This method can be used to load an assembly into a load context different from the load context of the currently executing assembly. +This method can be used to load an assembly into a load context different from the load context of the currently executing assembly. The assembly will be loaded into the load context on which the method is called. If the context can't resolve the assembly in its **Load** method the assembly loading will defer to the **Default** load context. In such case it's possible the loaded assembly is from the **Default** context even though the method was called on a non-default context. + +Calling this method directly on the **AssemblyLoadContext.Default** will only load the assembly from the **Default** context. Depending on the caller the **Default** may or may not be different from the load context of the currently executing assembly. + +This method does not "forcefully" load the assembly into the specified context. It basically initiates a bind to the specified assembly name on the specified context. That bind operation will go through the full binding resolution logic which is free to resolve the assembly from any context (in reality the most likely outcome is either the specified context or the default context). This process is described above. + +To make sure a specified assembly is loaded into the specified load context call **AssemblyLoadContext.LoadFromAssemblyPath** and specify the path to the assembly file. ### Resolving @@ -83,4 +89,4 @@ As part of .NET Standard 2.0 effort, certain assembly load APIs off the **Assemb * Assembly.LoadFile - creates a new (anonymous) load context to load the assembly into. * Assembly.Load(byte[]) - creates a new (anonymous) load context to load the assembly into. -If you need to influence the load process or the load context in which assemblies are loaded, please look at the various Load* APIs exposed by **AssemblyLoadContext** [API surface](https://github.com/dotnet/corefx/blob/master/src/System.Runtime.Loader/ref/System.Runtime.Loader.cs). \ No newline at end of file +If you need to influence the load process or the load context in which assemblies are loaded, please look at the various Load* APIs exposed by **AssemblyLoadContext** [API surface](https://github.com/dotnet/corefx/blob/master/src/System.Runtime.Loader/ref/System.Runtime.Loader.cs). -- 2.7.4