AssemblyLoadContext.LoadFromAssemblyName(AssemblyName) AssemblyLoadContext.LoadFromAssemblyName(AssemblyName) AssemblyLoadContext.LoadFromAssemblyName(AssemblyName) Method

定义

根据 AssemblyName 解析并加载程序集。Resolves and loads an assembly given its AssemblyName.

public:
 System::Reflection::Assembly ^ LoadFromAssemblyName(System::Reflection::AssemblyName ^ assemblyName);
public System.Reflection.Assembly LoadFromAssemblyName (System.Reflection.AssemblyName assemblyName);
member this.LoadFromAssemblyName : System.Reflection.AssemblyName -> System.Reflection.Assembly

参数

assemblyName
AssemblyName AssemblyName AssemblyName

描述要加载的程序集的对象。The object that describes the assembly to load.

返回

已加载程序集或引发事件。The loaded assembly, or throws.

异常

assemblyNamenullassemblyName is null.

assemblyName 未找到。assemblyName is not found.

assemblyName 不是有效的程序集。assemblyName is not a valid assembly.

加载了与 assemblyName 不匹配的程序集或模块。An assembly or module was loaded which did not match the assemblyName.

注解

LoadFromAssemblyName 加载程序集通过解决AssemblyNameLoadFromAssemblyName loads an assembly by resolving the AssemblyName. 这会触发完整的解决方法。This triggers a full resolution. 解析回退序列执行此过程:The resolution fallback sequence follows this process:

  1. 方法调用Load(AssemblyName)The method calls Load(AssemblyName).

    重要

    Load(AssemblyName) 必须调用此方法,以防止递归堆栈溢出。Load(AssemblyName) must not call this method to prevent recursive stack overflow.

  2. 除非加载程序集或引发异常,该方法会尝试加载程序集在默认AssemblyLoadContextUnless the assembly is loaded or an exception is thrown, the method attempts to load the assembly in the default AssemblyLoadContext.

  3. 除非加载程序集或引发异常,该方法将触发Resolving事件。Unless the assembly is loaded or an exception is thrown, the method fires the Resolving event.
  4. 除非加载程序集或引发异常,该方法将触发AssemblyResolve事件。Unless the assembly is loaded or an exception is thrown, the method fires the AssemblyResolve event.

备注

FileLoadException 如果引发assemblyRef指定完整的程序集名称和匹配的简单名称的第一个程序集具有不兼容的版本或区域性。FileLoadException is thrown if assemblyRef specifies the full assembly name, and the first assembly that matches the simple name has a incompatible version or culture. 加载程序不会继续探测的其他程序集的简单名称相匹配。The loader does not continue probing for other assemblies that match the simple name.

每个AssemblyLoadContext可以仅加载:Each AssemblyLoadContext can load only:

  • 可执行程序集的一个版本。One version of an executable assembly.
  • 每个区域性的附属程序集的一个版本。One version of a satellite assembly for each culture.

适用于