AppDomain.Load AppDomain.Load AppDomain.Load AppDomain.Load Method

定义

Assembly 加载到此应用程序域中。Loads an Assembly into this application domain.

重载

Load(Byte[]) Load(Byte[]) Load(Byte[]) Load(Byte[])

加载带有基于通用对象文件格式 (COFF) 的图像的 Assembly,该图像包含已发出的 AssemblyLoads the Assembly with a common object file format (COFF) based image containing an emitted Assembly.

Load(AssemblyName) Load(AssemblyName) Load(AssemblyName) Load(AssemblyName)

在给定 AssemblyName 的情况下加载 AssemblyLoads an Assembly given its AssemblyName.

Load(String) Load(String) Load(String) Load(String)

在给定其显示名称的情况下加载 AssemblyLoads an Assembly given its display name.

Load(Byte[], Byte[]) Load(Byte[], Byte[]) Load(Byte[], Byte[]) Load(Byte[], Byte[])

加载带有基于通用对象文件格式 (COFF) 的图像的 Assembly,该图像包含已发出的 AssemblyLoads the Assembly with a common object file format (COFF) based image containing an emitted Assembly. 还加载表示 Assembly 的符号的原始字节。The raw bytes representing the symbols for the Assembly are also loaded.

Load(AssemblyName, Evidence) Load(AssemblyName, Evidence) Load(AssemblyName, Evidence) Load(AssemblyName, Evidence)

在给定 AssemblyName 的情况下加载 AssemblyLoads an Assembly given its AssemblyName.

Load(String, Evidence) Load(String, Evidence) Load(String, Evidence) Load(String, Evidence)

在给定其显示名称的情况下加载 AssemblyLoads an Assembly given its display name.

Load(Byte[], Byte[], Evidence) Load(Byte[], Byte[], Evidence) Load(Byte[], Byte[], Evidence) Load(Byte[], Byte[], Evidence)

加载带有基于通用对象文件格式 (COFF) 的图像的 Assembly,该图像包含已发出的 AssemblyLoads the Assembly with a common object file format (COFF) based image containing an emitted Assembly. 还加载表示 Assembly 的符号的原始字节。The raw bytes representing the symbols for the Assembly are also loaded.

Load(Byte[]) Load(Byte[]) Load(Byte[]) Load(Byte[])

加载带有基于通用对象文件格式 (COFF) 的图像的 Assembly,该图像包含已发出的 AssemblyLoads the Assembly with a common object file format (COFF) based image containing an emitted Assembly.

public:
 virtual System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly);
public System.Reflection.Assembly Load (byte[] rawAssembly);
abstract member Load : byte[] -> System.Reflection.Assembly
override this.Load : byte[] -> System.Reflection.Assembly
Public Function Load (rawAssembly As Byte()) As Assembly

参数

rawAssembly
Byte[]

byte 类型的数组,它是包含已发出程序集的基于 COFF 的图像。An array of type byte that is a COFF-based image containing an emitted assembly.

返回

加载的程序集。The loaded assembly.

实现

异常

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

- 或 --or- 当前加载的是公共语言运行时 2.0 版或更高版本,而 rawAssembly 是用更高版本编译的。Version 2.0 or later of the common language runtime is currently loaded and rawAssembly was compiled with a later version.

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

一个程序集或模块用两个不同的证据加载了两次。An assembly or module was loaded twice with two different evidences.

示例

下面的示例演示如何加载原始程序集。The following sample demonstrates the use of loading a raw assembly.

若要运行此代码示例,必须提供完全限定的程序集名称。For this code example to run, you must provide the fully qualified assembly name. 有关如何获取完全限定的程序集名称的信息,请参阅程序集名称For information about how to obtain the fully qualified assembly name, see Assembly Names.

using namespace System;
using namespace System::IO;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
void InstantiateMyType( AppDomain^ domain )
{
   try
   {
      
      // You must supply a valid fully qualified assembly name here.
      domain->CreateInstance( "Assembly text name, Version, Culture, PublicKeyToken", "MyType" );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e->Message );
   }

}


// Loads the content of a file to a Byte array.
array<Byte>^ loadFile( String^ filename )
{
   FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
   array<Byte>^buffer = gcnew array<Byte>((int)fs->Length);
   fs->Read( buffer, 0, buffer->Length );
   fs->Close();
   return buffer;
}


// Creates a dynamic assembly with symbol information
// and saves them to temp.dll and temp.pdb
void EmitAssembly( AppDomain^ domain )
{
   AssemblyName^ assemblyName = gcnew AssemblyName;
   assemblyName->Name = "MyAssembly";
   AssemblyBuilder^ assemblyBuilder = domain->DefineDynamicAssembly( assemblyName, AssemblyBuilderAccess::Save );
   ModuleBuilder^ moduleBuilder = assemblyBuilder->DefineDynamicModule( "MyModule", "temp.dll", true );
   TypeBuilder^ typeBuilder = moduleBuilder->DefineType( "MyType", TypeAttributes::Public );
   ConstructorBuilder^ constructorBuilder = typeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, nullptr );
   ILGenerator^ ilGenerator = constructorBuilder->GetILGenerator();
   ilGenerator->EmitWriteLine( "MyType instantiated!" );
   ilGenerator->Emit( OpCodes::Ret );
   typeBuilder->CreateType();
   assemblyBuilder->Save( "temp.dll" );
}

ref class Resolver
{
public:
   static Assembly^ MyResolver( Object^ sender, ResolveEventArgs^ args )
   {
      AppDomain^ domain = dynamic_cast<AppDomain^>(sender);
      
      // Once the files are generated, this call is
      // actually no longer necessary.
      EmitAssembly( domain );
      array<Byte>^rawAssembly = loadFile( "temp.dll" );
      array<Byte>^rawSymbolStore = loadFile( "temp.pdb" );
      Assembly^ assembly = domain->Load( rawAssembly, rawSymbolStore );
      return assembly;
   }

};

int main()
{
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   InstantiateMyType( currentDomain ); // Failed!
   currentDomain->AssemblyResolve += gcnew ResolveEventHandler( Resolver::MyResolver );
   InstantiateMyType( currentDomain ); // OK!
}

using System;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;

class Test {
   public static void Main() {
      AppDomain currentDomain = AppDomain.CurrentDomain;
      
      InstantiateMyType(currentDomain);   // Failed!

      currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolver);
      
      InstantiateMyType(currentDomain);   // OK!
   }
   
   static void InstantiateMyType(AppDomain domain) {
      try {
     // You must supply a valid fully qualified assembly name here.
         domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType");
      } catch (Exception e) {
         Console.WriteLine(e.Message);
      }
   }
   
   // Loads the content of a file to a byte array. 
   static byte[] loadFile(string filename) {
      FileStream fs = new FileStream(filename, FileMode.Open);
      byte[] buffer = new byte[(int) fs.Length];
      fs.Read(buffer, 0, buffer.Length);
      fs.Close();
   
      return buffer;
   }   

   static Assembly MyResolver(object sender, ResolveEventArgs args) {
      AppDomain domain = (AppDomain) sender;

      // Once the files are generated, this call is
      // actually no longer necessary.
      EmitAssembly(domain);
      
      byte[] rawAssembly = loadFile("temp.dll");
      byte[] rawSymbolStore = loadFile("temp.pdb");
      Assembly assembly = domain.Load(rawAssembly, rawSymbolStore);

      return assembly;
   }
   
   // Creates a dynamic assembly with symbol information
   // and saves them to temp.dll and temp.pdb
   static void EmitAssembly(AppDomain domain) {
      AssemblyName assemblyName = new AssemblyName();
      assemblyName.Name = "MyAssembly";

      AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save);
      ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MyModule", "temp.dll", true);
      TypeBuilder typeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public);

      ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null);
      ILGenerator ilGenerator = constructorBuilder.GetILGenerator();
      ilGenerator.EmitWriteLine("MyType instantiated!");
      ilGenerator.Emit(OpCodes.Ret);

      typeBuilder.CreateType();
      
      assemblyBuilder.Save("temp.dll");
   }
}
Imports System.IO
Imports System.Reflection
Imports System.Reflection.Emit

Module Test
   
   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      
      InstantiateMyType(currentDomain)      ' Failed!

      AddHandler currentDomain.AssemblyResolve, AddressOf MyResolver
      
      InstantiateMyType(currentDomain)      ' OK!
   End Sub
   
   
   Sub InstantiateMyType(domain As AppDomain)
      Try
     ' You must supply a valid fully qualified assembly name here.
         domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType")
      Catch e As Exception
         Console.WriteLine(e.Message)
      End Try
   End Sub
   
   
   ' Loads the content of a file to a byte array. 
   Function loadFile(filename As String) As Byte()
      Dim fs As New FileStream(filename, FileMode.Open)
      Dim buffer(CInt(fs.Length - 1)) As Byte
      fs.Read(buffer, 0, buffer.Length)
      fs.Close()
      
      Return buffer
   End Function 'loadFile
   
   
   Function MyResolver(sender As Object, args As ResolveEventArgs) As System.Reflection.Assembly
      Dim domain As AppDomain = DirectCast(sender, AppDomain)
      
      ' Once the files are generated, this call is
      ' actually no longer necessary.
      EmitAssembly(domain)
      
      Dim rawAssembly As Byte() = loadFile("temp.dll")
      Dim rawSymbolStore As Byte() = loadFile("temp.pdb")
      Dim myAssembly As System.Reflection.Assembly = domain.Load(rawAssembly, rawSymbolStore)
      
      Return myAssembly
   End Function 'MyResolver
   
   
   ' Creates a dynamic assembly with symbol information
   ' and saves them to temp.dll and temp.pdb
   Sub EmitAssembly(domain As AppDomain)
      Dim assemblyName As New AssemblyName()
      assemblyName.Name = "MyAssembly"
      
      Dim assemblyBuilder As AssemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save)
      Dim moduleBuilder As ModuleBuilder = assemblyBuilder.DefineDynamicModule("MyModule", "temp.dll", True)
      Dim typeBuilder As TypeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public)
      
      Dim constructorBuilder As ConstructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Nothing)
      Dim ilGenerator As ILGenerator = constructorBuilder.GetILGenerator()
      ilGenerator.EmitWriteLine("MyType instantiated!")
      ilGenerator.Emit(OpCodes.Ret)
      
      typeBuilder.CreateType()
      
      assemblyBuilder.Save("temp.dll")
   End Sub

End Module 'Test

注解

从开始,使用此方法加载的程序集的信任级别与应用程序域的信任级别相同。 .NET Framework 4.NET Framework 4Beginning with the .NET Framework 4.NET Framework 4, the trust level of an assembly that is loaded by using this method is the same as the trust level of the application domain.

此方法只应用于将程序集加载到当前应用程序域中。This method should be used only to load an assembly into the current application domain. 提供此方法是为了为无法调用静态Assembly.Load方法的互操作性调用方提供便利。This method is provided as a convenience for interoperability callers who cannot call the static Assembly.Load method. 若要将程序集加载到其他应用程序域中, CreateInstanceAndUnwrap请使用方法(如)。To load assemblies into other application domains, use a method such as CreateInstanceAndUnwrap.

有关此方法的所有重载所共有的信息,请参阅Load(AssemblyName)方法重载。For information that is common to all overloads of this method, see the Load(AssemblyName) method overload.

安全性

FileIOPermission
用于从文件或目录读取的访问权限,以及用于访问路径本身中的信息的。for access to read from a file or directory, and for access to the information in the path itself. 关联的枚举ReadPathDiscovery、。Associated enumerations: Read, PathDiscovery.

Load(AssemblyName) Load(AssemblyName) Load(AssemblyName) Load(AssemblyName)

在给定 AssemblyName 的情况下加载 AssemblyLoads an Assembly given its AssemblyName.

public:
 virtual System::Reflection::Assembly ^ Load(System::Reflection::AssemblyName ^ assemblyRef);
public System.Reflection.Assembly Load (System.Reflection.AssemblyName assemblyRef);
abstract member Load : System.Reflection.AssemblyName -> System.Reflection.Assembly
override this.Load : System.Reflection.AssemblyName -> System.Reflection.Assembly
Public Function Load (assemblyRef As AssemblyName) As Assembly

参数

assemblyRef
AssemblyName AssemblyName AssemblyName AssemblyName

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

返回

加载的程序集。The loaded assembly.

实现

异常

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

-or- 当前加载的是公共语言运行时 2.0 版或更高版本,而 assemblyRef 是用更高版本编译的。Version 2.0 or later of the common language runtime is currently loaded and assemblyRef was compiled with a later version.

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

一个程序集或模块用两个不同的证据加载了两次。An assembly or module was loaded twice with two different evidences.

注解

此方法只应用于将程序集加载到当前应用程序域中。This method should be used only to load an assembly into the current application domain. 提供此方法是为了为无法调用静态Assembly.Load方法的互操作性调用方提供便利。This method is provided as a convenience for interoperability callers who cannot call the static Assembly.Load method. 若要将程序集加载到其他应用程序域中, CreateInstanceAndUnwrap请使用方法(如)。To load assemblies into other application domains, use a method such as CreateInstanceAndUnwrap.

如果已加载请求的程序集的版本,则即使请求了不同的版本,此方法也会返回已加载的程序集。If a version of the requested assembly is already loaded, this method returns the loaded assembly, even if a different version is requested.

不建议为提供部分程序assemblyRef集名称。Supplying a partial assembly name for assemblyRef is not recommended. (部分名称省略了一个或多个区域性、版本或公钥标记。(A partial name omits one or more of culture, version, or public key token. 对于采用字符串而不是AssemblyName对象的重载,"MyAssembly,version = 1.0.0.0" 是部分名称的示例,"MyAssembly,version = 1.0.0.0,Culture = 中立,PublicKeyToken = 18ab3442da84b47" 是全名的示例。)使用部分名称会对性能产生负面影响。For overloads that take a string instead of an AssemblyName object, "MyAssembly, Version=1.0.0.0" is an example of a partial name and "MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=18ab3442da84b47" is an example of a full name.) Using partial names has a negative effect on performance. 此外,仅当应用程序基目录(BaseDirectoryAppDomainSetup.ApplicationBase)中存在程序集的精确副本时,部分程序集名称才可以从全局程序集缓存加载程序集。In addition, a partial assembly name can load an assembly from the global assembly cache only if there is an exact copy of the assembly in the application base directory (BaseDirectory or AppDomainSetup.ApplicationBase).

如果当前AppDomain对象表示应用程序域A,并且Load从应用程序域B中调用方法,则会将程序集加载到这两个应用程序域中。If the current AppDomain object represents application domain A, and the Load method is called from application domain B, the assembly is loaded into both application domains. 例如,以下代码将加载到MyAssembly新应用程序域ChildDomain中,同时加载到代码执行的应用程序域中:For example, the following code loads MyAssembly into the new application domain ChildDomain and also into the application domain where the code executes:

AppDomain^ ad = AppDomain::CreateDomain("ChildDomain");
ad->Load("MyAssembly");
AppDomain ad = AppDomain.CreateDomain("ChildDomain");
ad.Load("MyAssembly");
Dim ad As AppDomain  = AppDomain.CreateDomain("ChildDomain")
ad.Load("MyAssembly")

由于Assembly不是从MarshalByRefObject派生的,因此程序集将加载到这两个域中,因此Load无法封送方法的返回值。The assembly is loaded into both domains because Assembly does not derive from MarshalByRefObject, and therefore the return value of the Load method cannot be marshaled. 相反,公共语言运行时尝试将程序集加载到调用应用程序域中。Instead, the common language runtime tries to load the assembly into the calling application domain. 如果两个应用程序域的路径设置不同,则加载到这两个应用程序域中的程序集可能会有所不同。The assemblies that are loaded into the two application domains might be different if the path settings for the two application domains are different.

备注

如果同时设置AssemblyName.Name了属性AssemblyName.CodeBase和属性,则第一次尝试加载程序集时将使用显示名称(包括版本、区域性等Assembly.FullName ,由属性返回)。If both the AssemblyName.Name property and the AssemblyName.CodeBase property are set, the first attempt to load the assembly uses the display name (including version, culture, and so on, as returned by the Assembly.FullName property). 如果找不到该文件,则CodeBase使用属性来搜索该程序集。If the file is not found, the CodeBase property is used to search for the assembly. 如果使用CodeBase找到程序集,则会将显示名称与程序集匹配。If the assembly is found using CodeBase, the display name is matched against the assembly. 如果匹配失败, FileLoadException则会引发。If the match fails, a FileLoadException is thrown.

安全性

FileIOPermission
用于从文件或目录读取的访问权限,以及用于访问路径本身中的信息的。for access to read from a file or directory, and for access to the information in the path itself. 关联的枚举ReadPathDiscovery、。Associated enumerations: Read, PathDiscovery.

Load(String) Load(String) Load(String) Load(String)

在给定其显示名称的情况下加载 AssemblyLoads an Assembly given its display name.

public:
 virtual System::Reflection::Assembly ^ Load(System::String ^ assemblyString);
public System.Reflection.Assembly Load (string assemblyString);
abstract member Load : string -> System.Reflection.Assembly
override this.Load : string -> System.Reflection.Assembly
Public Function Load (assemblyString As String) As Assembly

参数

assemblyString
String String String String

程序集的显示名称。The display name of the assembly. 请参阅 FullNameSee FullName.

返回

加载的程序集。The loaded assembly.

实现

异常

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

- 或 --or- 当前加载的是公共语言运行时 2.0 版或更高版本,而 assemblyString 是用更高版本编译的。Version 2.0 or later of the common language runtime is currently loaded and assemblyString was compiled with a later version.

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

一个程序集或模块用两个不同的证据加载了两次。An assembly or module was loaded twice with two different evidences.

注解

此方法只应用于将程序集加载到当前应用程序域中。This method should be used only to load an assembly into the current application domain. 提供此方法是为了为无法调用静态Assembly.Load方法的互操作性调用方提供便利。This method is provided as a convenience for interoperability callers who cannot call the static Assembly.Load method. 若要将程序集加载到其他应用程序域中, CreateInstanceAndUnwrap请使用方法(如)。To load assemblies into other application domains, use a method such as CreateInstanceAndUnwrap.

有关此方法的所有重载所共有的信息,请参阅Load(AssemblyName)方法重载。For information that is common to all overloads of this method, see the Load(AssemblyName) method overload.

安全性

FileIOPermission
用于从文件或目录读取的访问权限,以及用于访问路径本身中的信息的。for access to read from a file or directory, and for access to the information in the path itself. 关联的枚举ReadPathDiscovery、。Associated enumerations: Read, PathDiscovery.

WebPermission
如果程序集不是本地的,则能够访问程序集的位置。for the ability to access the location of the assembly if the assembly is not local.

Load(Byte[], Byte[]) Load(Byte[], Byte[]) Load(Byte[], Byte[]) Load(Byte[], Byte[])

加载带有基于通用对象文件格式 (COFF) 的图像的 Assembly,该图像包含已发出的 AssemblyLoads the Assembly with a common object file format (COFF) based image containing an emitted Assembly. 还加载表示 Assembly 的符号的原始字节。The raw bytes representing the symbols for the Assembly are also loaded.

public:
 virtual System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly, cli::array <System::Byte> ^ rawSymbolStore);
public System.Reflection.Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore);
abstract member Load : byte[] * byte[] -> System.Reflection.Assembly
override this.Load : byte[] * byte[] -> System.Reflection.Assembly
Public Function Load (rawAssembly As Byte(), rawSymbolStore As Byte()) As Assembly

参数

rawAssembly
Byte[]

byte 类型的数组,它是包含已发出程序集的基于 COFF 的图像。An array of type byte that is a COFF-based image containing an emitted assembly.

rawSymbolStore
Byte[]

byte 类型的数组,它包含表示程序集符号的原始字节。An array of type byte containing the raw bytes representing the symbols for the assembly.

返回

加载的程序集。The loaded assembly.

实现

异常

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

-or- 当前加载的是公共语言运行时 2.0 版或更高版本,而 rawAssembly 是用更高版本编译的。Version 2.0 or later of the common language runtime is currently loaded and rawAssembly was compiled with a later version.

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

一个程序集或模块用两个不同的证据加载了两次。An assembly or module was loaded twice with two different evidences.

示例

下面的示例演示如何加载原始程序集。The following sample demonstrates the use of loading a raw assembly.

若要运行此代码示例,必须提供完全限定的程序集名称。For this code example to run, you must provide the fully qualified assembly name. 有关如何获取完全限定的程序集名称的信息,请参阅程序集名称For information about how to obtain the fully qualified assembly name, see Assembly Names.

using namespace System;
using namespace System::IO;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
void InstantiateMyType( AppDomain^ domain )
{
   try
   {
      
      // You must supply a valid fully qualified assembly name here.
      domain->CreateInstance( "Assembly text name, Version, Culture, PublicKeyToken", "MyType" );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e->Message );
   }

}


// Loads the content of a file to a Byte array.
array<Byte>^ loadFile( String^ filename )
{
   FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
   array<Byte>^buffer = gcnew array<Byte>((int)fs->Length);
   fs->Read( buffer, 0, buffer->Length );
   fs->Close();
   return buffer;
}


// Creates a dynamic assembly with symbol information
// and saves them to temp.dll and temp.pdb
void EmitAssembly( AppDomain^ domain )
{
   AssemblyName^ assemblyName = gcnew AssemblyName;
   assemblyName->Name = "MyAssembly";
   AssemblyBuilder^ assemblyBuilder = domain->DefineDynamicAssembly( assemblyName, AssemblyBuilderAccess::Save );
   ModuleBuilder^ moduleBuilder = assemblyBuilder->DefineDynamicModule( "MyModule", "temp.dll", true );
   TypeBuilder^ typeBuilder = moduleBuilder->DefineType( "MyType", TypeAttributes::Public );
   ConstructorBuilder^ constructorBuilder = typeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, nullptr );
   ILGenerator^ ilGenerator = constructorBuilder->GetILGenerator();
   ilGenerator->EmitWriteLine( "MyType instantiated!" );
   ilGenerator->Emit( OpCodes::Ret );
   typeBuilder->CreateType();
   assemblyBuilder->Save( "temp.dll" );
}

ref class Resolver
{
public:
   static Assembly^ MyResolver( Object^ sender, ResolveEventArgs^ args )
   {
      AppDomain^ domain = dynamic_cast<AppDomain^>(sender);
      
      // Once the files are generated, this call is
      // actually no longer necessary.
      EmitAssembly( domain );
      array<Byte>^rawAssembly = loadFile( "temp.dll" );
      array<Byte>^rawSymbolStore = loadFile( "temp.pdb" );
      Assembly^ assembly = domain->Load( rawAssembly, rawSymbolStore );
      return assembly;
   }

};

int main()
{
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   InstantiateMyType( currentDomain ); // Failed!
   currentDomain->AssemblyResolve += gcnew ResolveEventHandler( Resolver::MyResolver );
   InstantiateMyType( currentDomain ); // OK!
}

using System;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;

class Test {
   public static void Main() {
      AppDomain currentDomain = AppDomain.CurrentDomain;
      
      InstantiateMyType(currentDomain);   // Failed!

      currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolver);
      
      InstantiateMyType(currentDomain);   // OK!
   }
   
   static void InstantiateMyType(AppDomain domain) {
      try {
     // You must supply a valid fully qualified assembly name here.
         domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType");
      } catch (Exception e) {
         Console.WriteLine(e.Message);
      }
   }
   
   // Loads the content of a file to a byte array. 
   static byte[] loadFile(string filename) {
      FileStream fs = new FileStream(filename, FileMode.Open);
      byte[] buffer = new byte[(int) fs.Length];
      fs.Read(buffer, 0, buffer.Length);
      fs.Close();
   
      return buffer;
   }   

   static Assembly MyResolver(object sender, ResolveEventArgs args) {
      AppDomain domain = (AppDomain) sender;

      // Once the files are generated, this call is
      // actually no longer necessary.
      EmitAssembly(domain);
      
      byte[] rawAssembly = loadFile("temp.dll");
      byte[] rawSymbolStore = loadFile("temp.pdb");
      Assembly assembly = domain.Load(rawAssembly, rawSymbolStore);

      return assembly;
   }
   
   // Creates a dynamic assembly with symbol information
   // and saves them to temp.dll and temp.pdb
   static void EmitAssembly(AppDomain domain) {
      AssemblyName assemblyName = new AssemblyName();
      assemblyName.Name = "MyAssembly";

      AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save);
      ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MyModule", "temp.dll", true);
      TypeBuilder typeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public);

      ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null);
      ILGenerator ilGenerator = constructorBuilder.GetILGenerator();
      ilGenerator.EmitWriteLine("MyType instantiated!");
      ilGenerator.Emit(OpCodes.Ret);

      typeBuilder.CreateType();
      
      assemblyBuilder.Save("temp.dll");
   }
}
Imports System.IO
Imports System.Reflection
Imports System.Reflection.Emit

Module Test
   
   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      
      InstantiateMyType(currentDomain)      ' Failed!

      AddHandler currentDomain.AssemblyResolve, AddressOf MyResolver
      
      InstantiateMyType(currentDomain)      ' OK!
   End Sub
   
   
   Sub InstantiateMyType(domain As AppDomain)
      Try
     ' You must supply a valid fully qualified assembly name here.
         domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType")
      Catch e As Exception
         Console.WriteLine(e.Message)
      End Try
   End Sub
   
   
   ' Loads the content of a file to a byte array. 
   Function loadFile(filename As String) As Byte()
      Dim fs As New FileStream(filename, FileMode.Open)
      Dim buffer(CInt(fs.Length - 1)) As Byte
      fs.Read(buffer, 0, buffer.Length)
      fs.Close()
      
      Return buffer
   End Function 'loadFile
   
   
   Function MyResolver(sender As Object, args As ResolveEventArgs) As System.Reflection.Assembly
      Dim domain As AppDomain = DirectCast(sender, AppDomain)
      
      ' Once the files are generated, this call is
      ' actually no longer necessary.
      EmitAssembly(domain)
      
      Dim rawAssembly As Byte() = loadFile("temp.dll")
      Dim rawSymbolStore As Byte() = loadFile("temp.pdb")
      Dim myAssembly As System.Reflection.Assembly = domain.Load(rawAssembly, rawSymbolStore)
      
      Return myAssembly
   End Function 'MyResolver
   
   
   ' Creates a dynamic assembly with symbol information
   ' and saves them to temp.dll and temp.pdb
   Sub EmitAssembly(domain As AppDomain)
      Dim assemblyName As New AssemblyName()
      assemblyName.Name = "MyAssembly"
      
      Dim assemblyBuilder As AssemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save)
      Dim moduleBuilder As ModuleBuilder = assemblyBuilder.DefineDynamicModule("MyModule", "temp.dll", True)
      Dim typeBuilder As TypeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public)
      
      Dim constructorBuilder As ConstructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Nothing)
      Dim ilGenerator As ILGenerator = constructorBuilder.GetILGenerator()
      ilGenerator.EmitWriteLine("MyType instantiated!")
      ilGenerator.Emit(OpCodes.Ret)
      
      typeBuilder.CreateType()
      
      assemblyBuilder.Save("temp.dll")
   End Sub

End Module 'Test

注解

从开始,使用此方法加载的程序集的信任级别与应用程序域的信任级别相同。 .NET Framework 4.NET Framework 4Beginning with the .NET Framework 4.NET Framework 4, the trust level of an assembly that is loaded by using this method is the same as the trust level of the application domain.

此方法只应用于将程序集加载到当前应用程序域中。This method should be used only to load an assembly into the current application domain. 提供此方法是为了为无法调用静态Assembly.Load方法的互操作性调用方提供便利。This method is provided as a convenience for interoperability callers who cannot call the static Assembly.Load method. 若要将程序集加载到其他应用程序域中, CreateInstanceAndUnwrap请使用方法(如)。To load assemblies into other application domains, use a method such as CreateInstanceAndUnwrap.

有关此方法的所有重载所共有的信息,请参阅Load(AssemblyName)方法重载。For information that is common to all overloads of this method, see the Load(AssemblyName) method overload.

安全性

WebPermission
用于读取不以 "file://" 开头的 URI。for reading a URI that does not begin with "file://".

FileIOPermission
用于从文件或目录读取的访问权限,以及用于访问路径本身中的信息的。for access to read from a file or directory, and for access to the information in the path itself. 关联的枚举ReadPathDiscovery、。Associated enumerations: Read, PathDiscovery.

Load(AssemblyName, Evidence) Load(AssemblyName, Evidence) Load(AssemblyName, Evidence) Load(AssemblyName, Evidence)

警告

此 API 现已过时。

在给定 AssemblyName 的情况下加载 AssemblyLoads an Assembly given its AssemblyName.

public:
 System::Reflection::Assembly ^ Load(System::Reflection::AssemblyName ^ assemblyRef, System::Security::Policy::Evidence ^ assemblySecurity);
[System.Obsolete("Use an overload that does not take an Evidence parameter")]
[System.Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public System.Reflection.Assembly Load (System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity);
member this.Load : System.Reflection.AssemblyName * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Function Load (assemblyRef As AssemblyName, assemblySecurity As Evidence) As Assembly

参数

assemblyRef
AssemblyName AssemblyName AssemblyName AssemblyName

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

assemblySecurity
Evidence Evidence Evidence Evidence

用于加载程序集的证据。Evidence for loading the assembly.

返回

加载的程序集。The loaded assembly.

实现

异常

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

-or- 当前加载的是公共语言运行时 2.0 版或更高版本,而 assemblyRef 是用更高版本编译的。Version 2.0 or later of the common language runtime is currently loaded and assemblyRef was compiled with a later version.

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

一个程序集或模块用两个不同的证据加载了两次。An assembly or module was loaded twice with two different evidences.

注解

此方法只应用于将程序集加载到当前应用程序域中。This method should be used only to load an assembly into the current application domain. 提供此方法是为了为无法调用静态Assembly.Load方法的互操作性调用方提供便利。This method is provided as a convenience for interoperability callers who cannot call the static Assembly.Load method. 若要将程序集加载到其他应用程序域中, CreateInstanceAndUnwrap请使用方法(如)。To load assemblies into other application domains, use a method such as CreateInstanceAndUnwrap.

有关此方法的所有重载所共有的信息,请参阅Load(AssemblyName)方法重载。For information that is common to all overloads of this method, see the Load(AssemblyName) method overload.

安全性

FileIOPermission
用于从文件或目录读取的访问权限,以及用于访问路径本身中的信息的。for access to read from a file or directory, and for access to the information in the path itself. 关联的枚举ReadPathDiscovery、。Associated enumerations: Read, PathDiscovery.

SecurityPermission
加载包含证据的程序集。to load an assembly with evidence. 关联的枚举:ControlEvidenceAssociated enumeration: ControlEvidence.

WebPermission
用于读取格式不是 "file://" 或 "\\\UNC\dir\\" 或 "c:\\" 的路径。for reading a path that is not in the form "file://" or "\\\UNC\dir\\" or "c:\\".

Load(String, Evidence) Load(String, Evidence) Load(String, Evidence) Load(String, Evidence)

警告

此 API 现已过时。

在给定其显示名称的情况下加载 AssemblyLoads an Assembly given its display name.

public:
 System::Reflection::Assembly ^ Load(System::String ^ assemblyString, System::Security::Policy::Evidence ^ assemblySecurity);
[System.Obsolete("Use an overload that does not take an Evidence parameter")]
[System.Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public System.Reflection.Assembly Load (string assemblyString, System.Security.Policy.Evidence assemblySecurity);
member this.Load : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Function Load (assemblyString As String, assemblySecurity As Evidence) As Assembly

参数

assemblyString
String String String String

程序集的显示名称。The display name of the assembly. 请参阅 FullNameSee FullName.

assemblySecurity
Evidence Evidence Evidence Evidence

用于加载程序集的证据。Evidence for loading the assembly.

返回

加载的程序集。The loaded assembly.

实现

异常

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

-or- 当前加载的是公共语言运行时 2.0 版或更高版本,而 assemblyString 是用更高版本编译的。Version 2.0 or later of the common language runtime is currently loaded and assemblyString was compiled with a later version.

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

一个程序集或模块用两个不同的证据加载了两次。An assembly or module was loaded twice with two different evidences.

注解

此方法只应用于将程序集加载到当前应用程序域中。This method should be used only to load an assembly into the current application domain. 提供此方法是为了为无法调用静态Assembly.Load方法的互操作性调用方提供便利。This method is provided as a convenience for interoperability callers who cannot call the static Assembly.Load method. 若要将程序集加载到其他应用程序域中, CreateInstanceAndUnwrap请使用方法(如)。To load assemblies into other application domains, use a method such as CreateInstanceAndUnwrap.

有关此方法的所有重载所共有的信息,请参阅Load(AssemblyName)方法重载。For information that is common to all overloads of this method, see the Load(AssemblyName) method overload.

安全性

SecurityPermission
加载包含证据的程序集。to load an assembly with evidence. 关联的枚举:ControlEvidenceAssociated enumeration: ControlEvidence.

FileIOPermission
用于从文件或目录读取的访问权限,以及用于访问路径本身中的信息的。for access to read from a file or directory, and for access to the information in the path itself. 关联的枚举ReadPathDiscovery、。Associated enumerations: Read, PathDiscovery.

WebPermission
用于读取格式不是 "file://" 或 "\\\UNC\dir\\" 或 "c:\\" 的路径。for reading a path that is not in the form "file://" or "\\\UNC\dir\\" or "c:\\".

Load(Byte[], Byte[], Evidence) Load(Byte[], Byte[], Evidence) Load(Byte[], Byte[], Evidence) Load(Byte[], Byte[], Evidence)

警告

此 API 现已过时。

加载带有基于通用对象文件格式 (COFF) 的图像的 Assembly,该图像包含已发出的 AssemblyLoads the Assembly with a common object file format (COFF) based image containing an emitted Assembly. 还加载表示 Assembly 的符号的原始字节。The raw bytes representing the symbols for the Assembly are also loaded.

public:
 System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly, cli::array <System::Byte> ^ rawSymbolStore, System::Security::Policy::Evidence ^ securityEvidence);
[System.Obsolete("Use an overload that does not take an Evidence parameter")]
[System.Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkId=155570 for more information.")]
public System.Reflection.Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore, System.Security.Policy.Evidence securityEvidence);
member this.Load : byte[] * byte[] * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Function Load (rawAssembly As Byte(), rawSymbolStore As Byte(), securityEvidence As Evidence) As Assembly

参数

rawAssembly
Byte[]

byte 类型的数组,它是包含已发出程序集的基于 COFF 的图像。An array of type byte that is a COFF-based image containing an emitted assembly.

rawSymbolStore
Byte[]

byte 类型的数组,它包含表示程序集符号的原始字节。An array of type byte containing the raw bytes representing the symbols for the assembly.

securityEvidence
Evidence Evidence Evidence Evidence

用于加载程序集的证据。Evidence for loading the assembly.

返回

加载的程序集。The loaded assembly.

实现

异常

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

- 或 --or- 当前加载的是公共语言运行时 2.0 版或更高版本,而 rawAssembly 是用更高版本编译的。Version 2.0 or later of the common language runtime is currently loaded and rawAssembly was compiled with a later version.

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

一个程序集或模块用两个不同的证据加载了两次。An assembly or module was loaded twice with two different evidences.

securityEvidence 不是 nullsecurityEvidence is not null. 未启用旧版 CAS 策略时,securityEvidence 应为 nullWhen legacy CAS policy is not enabled, securityEvidence should be null.

示例

下面的示例演示如何加载原始程序集。The following sample demonstrates the use of loading a raw assembly.

若要运行此代码示例,必须提供完全限定的程序集名称。For this code example to run, you must provide the fully qualified assembly name. 有关如何获取完全限定的程序集名称的信息,请参阅程序集名称For information about how to obtain the fully qualified assembly name, see Assembly Names.

using namespace System;
using namespace System::IO;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
void InstantiateMyType( AppDomain^ domain )
{
   try
   {
      
      // You must supply a valid fully qualified assembly name here.
      domain->CreateInstance( "Assembly text name, Version, Culture, PublicKeyToken", "MyType" );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e->Message );
   }

}


// Loads the content of a file to a Byte array.
array<Byte>^ loadFile( String^ filename )
{
   FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
   array<Byte>^buffer = gcnew array<Byte>((int)fs->Length);
   fs->Read( buffer, 0, buffer->Length );
   fs->Close();
   return buffer;
}


// Creates a dynamic assembly with symbol information
// and saves them to temp.dll and temp.pdb
void EmitAssembly( AppDomain^ domain )
{
   AssemblyName^ assemblyName = gcnew AssemblyName;
   assemblyName->Name = "MyAssembly";
   AssemblyBuilder^ assemblyBuilder = domain->DefineDynamicAssembly( assemblyName, AssemblyBuilderAccess::Save );
   ModuleBuilder^ moduleBuilder = assemblyBuilder->DefineDynamicModule( "MyModule", "temp.dll", true );
   TypeBuilder^ typeBuilder = moduleBuilder->DefineType( "MyType", TypeAttributes::Public );
   ConstructorBuilder^ constructorBuilder = typeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, nullptr );
   ILGenerator^ ilGenerator = constructorBuilder->GetILGenerator();
   ilGenerator->EmitWriteLine( "MyType instantiated!" );
   ilGenerator->Emit( OpCodes::Ret );
   typeBuilder->CreateType();
   assemblyBuilder->Save( "temp.dll" );
}

ref class Resolver
{
public:
   static Assembly^ MyResolver( Object^ sender, ResolveEventArgs^ args )
   {
      AppDomain^ domain = dynamic_cast<AppDomain^>(sender);
      
      // Once the files are generated, this call is
      // actually no longer necessary.
      EmitAssembly( domain );
      array<Byte>^rawAssembly = loadFile( "temp.dll" );
      array<Byte>^rawSymbolStore = loadFile( "temp.pdb" );
      Assembly^ assembly = domain->Load( rawAssembly, rawSymbolStore );
      return assembly;
   }

};

int main()
{
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   InstantiateMyType( currentDomain ); // Failed!
   currentDomain->AssemblyResolve += gcnew ResolveEventHandler( Resolver::MyResolver );
   InstantiateMyType( currentDomain ); // OK!
}

using System;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;

class Test {
   public static void Main() {
      AppDomain currentDomain = AppDomain.CurrentDomain;
      
      InstantiateMyType(currentDomain);   // Failed!

      currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolver);
      
      InstantiateMyType(currentDomain);   // OK!
   }
   
   static void InstantiateMyType(AppDomain domain) {
      try {
     // You must supply a valid fully qualified assembly name here.
         domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType");
      } catch (Exception e) {
         Console.WriteLine(e.Message);
      }
   }
   
   // Loads the content of a file to a byte array. 
   static byte[] loadFile(string filename) {
      FileStream fs = new FileStream(filename, FileMode.Open);
      byte[] buffer = new byte[(int) fs.Length];
      fs.Read(buffer, 0, buffer.Length);
      fs.Close();
   
      return buffer;
   }   

   static Assembly MyResolver(object sender, ResolveEventArgs args) {
      AppDomain domain = (AppDomain) sender;

      // Once the files are generated, this call is
      // actually no longer necessary.
      EmitAssembly(domain);
      
      byte[] rawAssembly = loadFile("temp.dll");
      byte[] rawSymbolStore = loadFile("temp.pdb");
      Assembly assembly = domain.Load(rawAssembly, rawSymbolStore);

      return assembly;
   }
   
   // Creates a dynamic assembly with symbol information
   // and saves them to temp.dll and temp.pdb
   static void EmitAssembly(AppDomain domain) {
      AssemblyName assemblyName = new AssemblyName();
      assemblyName.Name = "MyAssembly";

      AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save);
      ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MyModule", "temp.dll", true);
      TypeBuilder typeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public);

      ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null);
      ILGenerator ilGenerator = constructorBuilder.GetILGenerator();
      ilGenerator.EmitWriteLine("MyType instantiated!");
      ilGenerator.Emit(OpCodes.Ret);

      typeBuilder.CreateType();
      
      assemblyBuilder.Save("temp.dll");
   }
}
Imports System.IO
Imports System.Reflection
Imports System.Reflection.Emit

Module Test
   
   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      
      InstantiateMyType(currentDomain)      ' Failed!

      AddHandler currentDomain.AssemblyResolve, AddressOf MyResolver
      
      InstantiateMyType(currentDomain)      ' OK!
   End Sub
   
   
   Sub InstantiateMyType(domain As AppDomain)
      Try
     ' You must supply a valid fully qualified assembly name here.
         domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType")
      Catch e As Exception
         Console.WriteLine(e.Message)
      End Try
   End Sub
   
   
   ' Loads the content of a file to a byte array. 
   Function loadFile(filename As String) As Byte()
      Dim fs As New FileStream(filename, FileMode.Open)
      Dim buffer(CInt(fs.Length - 1)) As Byte
      fs.Read(buffer, 0, buffer.Length)
      fs.Close()
      
      Return buffer
   End Function 'loadFile
   
   
   Function MyResolver(sender As Object, args As ResolveEventArgs) As System.Reflection.Assembly
      Dim domain As AppDomain = DirectCast(sender, AppDomain)
      
      ' Once the files are generated, this call is
      ' actually no longer necessary.
      EmitAssembly(domain)
      
      Dim rawAssembly As Byte() = loadFile("temp.dll")
      Dim rawSymbolStore As Byte() = loadFile("temp.pdb")
      Dim myAssembly As System.Reflection.Assembly = domain.Load(rawAssembly, rawSymbolStore)
      
      Return myAssembly
   End Function 'MyResolver
   
   
   ' Creates a dynamic assembly with symbol information
   ' and saves them to temp.dll and temp.pdb
   Sub EmitAssembly(domain As AppDomain)
      Dim assemblyName As New AssemblyName()
      assemblyName.Name = "MyAssembly"
      
      Dim assemblyBuilder As AssemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save)
      Dim moduleBuilder As ModuleBuilder = assemblyBuilder.DefineDynamicModule("MyModule", "temp.dll", True)
      Dim typeBuilder As TypeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public)
      
      Dim constructorBuilder As ConstructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Nothing)
      Dim ilGenerator As ILGenerator = constructorBuilder.GetILGenerator()
      ilGenerator.EmitWriteLine("MyType instantiated!")
      ilGenerator.Emit(OpCodes.Ret)
      
      typeBuilder.CreateType()
      
      assemblyBuilder.Save("temp.dll")
   End Sub

End Module 'Test

注解

从开始,使用此方法加载的程序集的信任级别与应用程序域的信任级别相同。 .NET Framework 4.NET Framework 4Beginning with the .NET Framework 4.NET Framework 4, the trust level of an assembly that is loaded by using this method is the same as the trust level of the application domain.

此方法只应用于将程序集加载到当前应用程序域中。This method should be used only to load an assembly into the current application domain. 提供此方法是为了为无法调用静态Assembly.Load方法的互操作性调用方提供便利。This method is provided as a convenience for interoperability callers who cannot call the static Assembly.Load method. 若要将程序集加载到其他应用程序域中, CreateInstanceAndUnwrap请使用方法(如)。To load assemblies into other application domains, use a method such as CreateInstanceAndUnwrap.

有关此方法的所有重载所共有的信息,请参阅Load(AssemblyName)方法重载。For information that is common to all overloads of this method, see the Load(AssemblyName) method overload.

安全性

SecurityPermission
提供证据。to provide evidence. 关联的枚举:ControlEvidenceAssociated enumeration: ControlEvidence. 安全操作: DemandSecurity action: Demand.

FileIOPermission
用于从文件或目录读取的访问权限,以及用于访问路径本身中的信息的。for access to read from a file or directory, and for access to the information in the path itself. 关联的枚举ReadPathDiscovery、。Associated enumerations: Read, PathDiscovery.

WebPermission
用于读取格式不是 "file://" 或 "\\\UNC\dir\\" 或 "c:\\" 的路径。for reading a path that is not in the form "file://" or "\\\UNC\dir\\" or "c:\\".

适用于