Notiz
Zougrëff op dës Säit erfuerdert Autorisatioun. Dir kënnt probéieren, Iech unzemellen oder Verzeechnesser ze änneren.
Zougrëff op dës Säit erfuerdert Autorisatioun. Dir kënnt probéieren, Verzeechnesser ze änneren.
Managed assemblies are located and loaded with an algorithm that has various stages.
All managed assemblies except satellite assemblies and WinRT assemblies use the same algorithm.
When are managed assemblies loaded?
The most common mechanism to trigger a managed assembly load is a static assembly reference. These references are inserted by the compiler whenever code uses a type defined in another assembly. These assemblies are loaded (load-by-name) as needed by the runtime. The exact timing of when the static assembly references are loaded is unspecified. It can vary between runtime versions and is influenced by optimizations like inlining.
The direct use of the following APIs will also trigger loads:
Important
Unlike .NET Framework, the assemblyFile parameter of Assembly.LoadFrom is treated as a file path in .NET, not a URI. In .NET Framework, you can pass a file URI (for example, file:///C:/path/to/assembly.dll)—such as one constructed from Assembly.CodeBase—and the assembly loads successfully. In .NET, the assemblyFile value is passed to Path.GetFullPath, which doesn't properly handle URIs, so the load fails. If you already have a file URI string, first create a Uri instance and use its LocalPath property to get the file path before calling Assembly.LoadFrom. To get the file path of an already-loaded assembly, use Assembly.Location instead of CodeBase.
Algorithm
The following algorithm describes how the runtime loads a managed assembly.
Determine the
activeAssemblyLoadContext.- For a static assembly reference, the
activeAssemblyLoadContext is the instance that loaded the referring assembly. - Preferred APIs make the
activeAssemblyLoadContext explicit. - Other APIs infer the
activeAssemblyLoadContext. For these APIs, the AssemblyLoadContext.CurrentContextualReflectionContext property is used. If its value isnull, then the inferred AssemblyLoadContext instance is used. - See the table in the When are managed assemblies loaded? section.
- For a static assembly reference, the
For the
Load-by-namemethods, theactiveAssemblyLoadContext loads the assembly in the following priority order:- Check its
cache-by-name. - Call the AssemblyLoadContext.Load function.
- Check the AssemblyLoadContext.Default instance's cache and run managed assembly default probing logic. If an assembly is newly loaded, a reference is added to the AssemblyLoadContext.Default instance's
cache-by-name. - Raise the AssemblyLoadContext.Resolving event for the active AssemblyLoadContext.
- Raise the AppDomain.AssemblyResolve event.
- Check its
For the other types of loads, the
activeAssemblyLoadContext loads the assembly in the following priority order:- Check its
cache-by-name. - If the
activeAssemblyLoadContext is AssemblyLoadContext.Default, run the default probing logic for managed assemblies. - Load from the specified path or raw assembly object. If an assembly is newly loaded, a reference is added to the
activeAssemblyLoadContext instance'scache-by-name.
- Check its
In either case, if an assembly is newly loaded, then the AppDomain.AssemblyLoad event is raised.