|
24 | 24 | <summary>Represents the runtime's concept of a scope for assembly loading.</summary>
|
25 | 25 | <remarks>
|
26 | 26 | <format type="text/markdown"><![CDATA[
|
27 |
| -
|
28 | 27 | ## Remarks
|
29 |
| - The <xref:System.Runtime.Loader.AssemblyLoadContext> represents a load context. Conceptually, a load context creates a scope for loading, resolving, and potentially unloading a set of assemblies. |
| 28 | +
|
| 29 | +The <xref:System.Runtime.Loader.AssemblyLoadContext> represents a load context. Conceptually, a load context creates a scope for loading, resolving, and potentially unloading a set of assemblies. |
30 | 30 |
|
31 |
| - <xref:System.Runtime.Loader.AssemblyLoadContext> is an abstract class. The <xref:System.Runtime.Loader.AssemblyLoadContext.Load(System.Reflection.AssemblyName)?displayProperty=nameWithType> needs to be implemented to create a concrete class. |
| 31 | +<xref:System.Runtime.Loader.AssemblyLoadContext> is an abstract class. The <xref:System.Runtime.Loader.AssemblyLoadContext.Load(System.Reflection.AssemblyName)?displayProperty=nameWithType> method needs to be implemented to create a concrete class. |
32 | 32 |
|
33 |
| - The <xref:System.Runtime.Loader.AssemblyLoadContext> exists primarily to provide assembly loading isolation. It allows multiple versions of the same assembly to be loaded within a single process. It replaces the isolation mechanisms provided by multiple <xref:System.AppDomain> instances in the .NET Framework. |
| 33 | +The <xref:System.Runtime.Loader.AssemblyLoadContext> exists primarily to provide assembly loading isolation. It allows multiple versions of the same assembly to be loaded within a single process. It replaces the isolation mechanisms provided by multiple <xref:System.AppDomain> instances in the .NET Framework. |
34 | 34 |
|
35 |
| - > [!NOTE] |
36 |
| - > <xref:System.Runtime.Loader.AssemblyLoadContext> does not provide any security features. All code has full permissions of the process. |
| 35 | +> [!NOTE] |
| 36 | +> <xref:System.Runtime.Loader.AssemblyLoadContext> does not provide any security features. All code has full permissions of the process. |
37 | 37 |
|
38 | 38 | ### Usage in the runtime
|
39 |
| - The runtime implements two assembly load contexts: |
40 |
| - * <xref:System.Runtime.Loader.AssemblyLoadContext.Default?displayProperty=nameWithType> represents the runtime's default context which is used for the application main assembly and its static dependencies. |
41 |
| - * The <xref:System.Reflection.Assembly.LoadFile(System.String)?displayProperty=nameWithType> method isolates the assemblies it loads by instantiating the most basic <xref:System.Runtime.Loader.AssemblyLoadContext>. It has a simplistic isolation scheme which loads each assembly in its own <xref:System.Runtime.Loader.AssemblyLoadContext> with no dependency resolution. |
| 39 | +
|
| 40 | +The runtime implements two assembly load contexts: |
| 41 | +
|
| 42 | +* <xref:System.Runtime.Loader.AssemblyLoadContext.Default?displayProperty=nameWithType> represents the runtime's default context, which is used for the application main assembly and its static dependencies. |
| 43 | +* The <xref:System.Reflection.Assembly.LoadFile(System.String)?displayProperty=nameWithType> method isolates the assemblies it loads by instantiating the most basic <xref:System.Runtime.Loader.AssemblyLoadContext>. It has a simplistic isolation scheme that loads each assembly in its own <xref:System.Runtime.Loader.AssemblyLoadContext> with no dependency resolution. |
42 | 44 |
|
43 | 45 | ### Application usage
|
44 |
| - An application can create its own <xref:System.Runtime.Loader.AssemblyLoadContext> to create a custom solution for advanced scenarios. The customization focuses on defining dependency resolution mechanisms. |
| 46 | +
|
| 47 | +An application can create its own <xref:System.Runtime.Loader.AssemblyLoadContext> to create a custom solution for advanced scenarios. The customization focuses on defining dependency resolution mechanisms. |
45 | 48 |
|
46 |
| - The <xref:System.Runtime.Loader.AssemblyLoadContext> provides two extension points to implement managed assembly resolution: |
47 |
| - 1. The <xref:System.Runtime.Loader.AssemblyLoadContext.Load(System.Reflection.AssemblyName)?displayProperty=nameWithType> provides the first chance for the <xref:System.Runtime.Loader.AssemblyLoadContext> to resolve the assembly, load it and return it. If the <xref:System.Runtime.Loader.AssemblyLoadContext.Load(System.Reflection.AssemblyName)?displayProperty=nameWithType> returns `null`, the loader will try to load the assembly into the <xref:System.Runtime.Loader.AssemblyLoadContext.Default?displayProperty=nameWithType>. |
48 |
| - 2. If the <xref:System.Runtime.Loader.AssemblyLoadContext.Default?displayProperty=nameWithType> is unable to resolve the assembly, the original <xref:System.Runtime.Loader.AssemblyLoadContext> gets a second chance to resolve the assembly. The runtime raises the <xref:System.Runtime.Loader.AssemblyLoadContext.Resolving> event. |
| 49 | +The <xref:System.Runtime.Loader.AssemblyLoadContext> provides two extension points to implement managed assembly resolution: |
| 50 | +
|
| 51 | +1. The <xref:System.Runtime.Loader.AssemblyLoadContext.Load(System.Reflection.AssemblyName)?displayProperty=nameWithType> method provides the first chance for the <xref:System.Runtime.Loader.AssemblyLoadContext> to resolve, load, and return the assembly. If the <xref:System.Runtime.Loader.AssemblyLoadContext.Load(System.Reflection.AssemblyName)?displayProperty=nameWithType> method returns `null`, the loader tries to load the assembly into the <xref:System.Runtime.Loader.AssemblyLoadContext.Default?displayProperty=nameWithType>. |
| 52 | +2. If the <xref:System.Runtime.Loader.AssemblyLoadContext.Default?displayProperty=nameWithType> is unable to resolve the assembly, the original <xref:System.Runtime.Loader.AssemblyLoadContext> gets a second chance to resolve the assembly. The runtime raises the <xref:System.Runtime.Loader.AssemblyLoadContext.Resolving> event. |
49 | 53 |
|
50 |
| - Additionally the <xref:System.Runtime.Loader.AssemblyLoadContext.LoadUnmanagedDll(System.String)?displayProperty=nameWithType> virtual method allows customization of the default unmanaged assembly resolution. The default implementation returns `null`, which causes the runtime search to use its default search policy which is sufficient for most scenarios. |
| 54 | +Additionally, the <xref:System.Runtime.Loader.AssemblyLoadContext.LoadUnmanagedDll(System.String)?displayProperty=nameWithType> virtual method allows customization of the default unmanaged assembly resolution. The default implementation returns `null`, which causes the runtime search to use its default search policy. The default search policy is sufficient for most scenarios. |
51 | 55 |
|
52 | 56 | ### Technical challenges
|
53 |
| - * It is not possible to load multiple versions of the runtime in a single process. |
| 57 | +
|
| 58 | +* It is not possible to load multiple versions of the runtime in a single process. |
| 59 | +
|
54 | 60 | > [!CAUTION]
|
55 |
| - > Loading multiple copies or different versions of framework assemblies can lead to unexpected and hard to diagnose behavior. |
| 61 | + > Loading multiple copies or different versions of framework assemblies can lead to unexpected and hard-to-diagnose behavior. |
56 | 62 |
|
57 | 63 | > [!TIP]
|
58 |
| - > Use process boundaries with remoting and/or interprocess communication to solve this isolation problem. |
| 64 | + > Use process boundaries with remoting or interprocess communication to solve this isolation problem. |
59 | 65 |
|
60 |
| - * The timing of assembly loading can make testing and debugging difficult. Assemblies are typically loaded without their dependencies immediately being resolved. The dependencies are loaded as they are needed: |
| 66 | +* The timing of assembly loading can make testing and debugging difficult. Assemblies are typically loaded without their dependencies immediately being resolved. The dependencies are loaded as they are needed: |
| 67 | +
|
61 | 68 | * When code branches into a dependent assembly.
|
62 | 69 | * When code loads resources.
|
63 | 70 | * When code explicitly loads assemblies.
|
64 | 71 |
|
65 |
| - * The implementation of <xref:System.Runtime.Loader.AssemblyLoadContext.Load(System.Reflection.AssemblyName)?displayProperty=nameWithType> can add new dependencies which may need to be isolated to allow different versions to exist. The most natural implementation would place these dependencies in the default context. Careful design can isolate the new dependencies. |
| 72 | +* The implementation of <xref:System.Runtime.Loader.AssemblyLoadContext.Load(System.Reflection.AssemblyName)?displayProperty=nameWithType> can add new dependencies that may need to be isolated to allow different versions to exist. The most natural implementation would place these dependencies in the default context. Careful design can isolate the new dependencies. |
66 | 73 |
|
67 |
| - * The same assembly is loaded multiple times into different contexts. |
68 |
| - * This can lead to confusing error messages, for example "Unable to cast object of type 'Sample.Plugin' to type 'Sample.Plugin'." |
69 |
| - * Marshaling across isolation boundaries is non-trivial. A typical solution would be to use an interface defined in an assembly which is only loaded into the default load context. |
| 74 | +* The same assembly is loaded multiple times into different contexts. |
| 75 | + * This can lead to confusing error messages, for example "Unable to cast object of type 'Sample.Plugin' to type 'Sample.Plugin'". |
| 76 | + * Marshaling across isolation boundaries is non-trivial. A typical solution is to use an interface defined in an assembly that's only loaded into the default load context. |
70 | 77 |
|
71 | 78 | ]]></format>
|
72 | 79 | </remarks>
|
|
0 commit comments