AppDomain.Load 方法
定义
重载
Load(Byte[]) |
加载带有基于通用对象文件格式 (COFF) 的图像的 Assembly,该图像包含已发出的 Assembly。Loads the Assembly with a common object file format (COFF) based image containing an emitted Assembly. |
Load(AssemblyName) |
在给定 AssemblyName 的情况下加载 Assembly。Loads an Assembly given its AssemblyName. |
Load(String) |
在给定其显示名称的情况下加载 Assembly。Loads an Assembly given its display name. |
Load(Byte[], Byte[]) |
加载带有基于通用对象文件格式 (COFF) 的图像的 Assembly,该图像包含已发出的 Assembly。Loads 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) |
已过时。
已过时。
在给定 AssemblyName 的情况下加载 Assembly。Loads an Assembly given its AssemblyName. |
Load(String, Evidence) |
已过时。
已过时。
在给定其显示名称的情况下加载 Assembly。Loads an Assembly given its display name. |
Load(Byte[], Byte[], Evidence) |
已过时。
已过时。
加载带有基于通用对象文件格式 (COFF) 的图像的 Assembly,该图像包含已发出的 Assembly。Loads 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[])
public:
System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly);
public:
virtual System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly);
public System.Reflection.Assembly Load (byte[] rawAssembly);
member this.Load : byte[] -> System.Reflection.Assembly
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
为 null
。rawAssembly
is null
.
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 开始,使用此方法加载的程序集的信任级别与应用程序域的信任级别相同。Beginning with the .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.
适用于
Load(AssemblyName)
在给定 AssemblyName 的情况下加载 Assembly。Loads an Assembly given its AssemblyName.
public:
System::Reflection::Assembly ^ Load(System::Reflection::AssemblyName ^ assemblyRef);
public:
virtual System::Reflection::Assembly ^ Load(System::Reflection::AssemblyName ^ assemblyRef);
public System.Reflection.Assembly Load (System.Reflection.AssemblyName assemblyRef);
member this.Load : System.Reflection.AssemblyName -> System.Reflection.Assembly
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
描述要加载的程序集的对象。An object that describes the assembly to load.
返回
加载的程序集。The loaded assembly.
实现
例外
assemblyRef
为 null
。assemblyRef
is null
.
assemblyRef
未找到。assemblyRef
is not found.
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. 此外,仅当应用程序基目录中存在程序集的精确副本 (或) 时,部分程序集名称才可以从全局程序集缓存加载程序集 BaseDirectory AppDomainSetup.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.
适用于
Load(String)
public:
System::Reflection::Assembly ^ Load(System::String ^ assemblyString);
public:
virtual System::Reflection::Assembly ^ Load(System::String ^ assemblyString);
public System.Reflection.Assembly Load (string assemblyString);
member this.Load : string -> System.Reflection.Assembly
abstract member Load : string -> System.Reflection.Assembly
override this.Load : string -> System.Reflection.Assembly
Public Function Load (assemblyString As String) As Assembly
参数
返回
加载的程序集。The loaded assembly.
实现
例外
assemblyString
为 null
assemblyString
is null
assemblyString
未找到。assemblyString
is not found.
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.
适用于
Load(Byte[], Byte[])
public:
System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly, cli::array <System::Byte> ^ rawSymbolStore);
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);
public System.Reflection.Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore);
member this.Load : byte[] * byte[] -> System.Reflection.Assembly
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
为 null
。rawAssembly
is null
.
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 开始,使用此方法加载的程序集的信任级别与应用程序域的信任级别相同。Beginning with the .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.
适用于
Load(AssemblyName, Evidence)
注意
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.
注意
Use an overload that does not take an Evidence parameter
在给定 AssemblyName 的情况下加载 Assembly。Loads an Assembly given its AssemblyName.
public:
virtual System::Reflection::Assembly ^ Load(System::Reflection::AssemblyName ^ assemblyRef, System::Security::Policy::Evidence ^ assemblySecurity);
public:
System::Reflection::Assembly ^ Load(System::Reflection::AssemblyName ^ assemblyRef, System::Security::Policy::Evidence ^ assemblySecurity);
public System.Reflection.Assembly Load (System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity);
[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);
[System.Obsolete("Use an overload that does not take an Evidence parameter")]
public System.Reflection.Assembly Load (System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity);
abstract member Load : System.Reflection.AssemblyName * System.Security.Policy.Evidence -> System.Reflection.Assembly
override this.Load : System.Reflection.AssemblyName * System.Security.Policy.Evidence -> System.Reflection.Assembly
[<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.")>]
abstract member Load : System.Reflection.AssemblyName * System.Security.Policy.Evidence -> System.Reflection.Assembly
override this.Load : System.Reflection.AssemblyName * System.Security.Policy.Evidence -> System.Reflection.Assembly
[<System.Obsolete("Use an overload that does not take an Evidence parameter")>]
member this.Load : System.Reflection.AssemblyName * System.Security.Policy.Evidence -> System.Reflection.Assembly
[<System.Obsolete("Use an overload that does not take an Evidence parameter")>]
abstract member Load : System.Reflection.AssemblyName * System.Security.Policy.Evidence -> System.Reflection.Assembly
override 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
描述要加载的程序集的对象。An object that describes the assembly to load.
- assemblySecurity
- Evidence
用于加载程序集的证据。Evidence for loading the assembly.
返回
加载的程序集。The loaded assembly.
实现
- 属性
例外
assemblyRef
为 null
assemblyRef
is null
assemblyRef
未找到。assemblyRef
is not found.
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.
适用于
Load(String, Evidence)
注意
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.
注意
Use an overload that does not take an Evidence parameter
public:
virtual System::Reflection::Assembly ^ Load(System::String ^ assemblyString, System::Security::Policy::Evidence ^ assemblySecurity);
public:
System::Reflection::Assembly ^ Load(System::String ^ assemblyString, System::Security::Policy::Evidence ^ assemblySecurity);
public System.Reflection.Assembly Load (string assemblyString, System.Security.Policy.Evidence assemblySecurity);
[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);
[System.Obsolete("Use an overload that does not take an Evidence parameter")]
public System.Reflection.Assembly Load (string assemblyString, System.Security.Policy.Evidence assemblySecurity);
abstract member Load : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
override this.Load : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
[<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.")>]
abstract member Load : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
override this.Load : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
[<System.Obsolete("Use an overload that does not take an Evidence parameter")>]
member this.Load : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
[<System.Obsolete("Use an overload that does not take an Evidence parameter")>]
abstract member Load : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
override this.Load : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Function Load (assemblyString As String, assemblySecurity As Evidence) As Assembly
参数
- assemblySecurity
- Evidence
用于加载程序集的证据。Evidence for loading the assembly.
返回
加载的程序集。The loaded assembly.
实现
- 属性
例外
assemblyString
为 null
assemblyString
is null
assemblyString
未找到。assemblyString
is not found.
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.
适用于
Load(Byte[], Byte[], Evidence)
注意
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.
注意
Use an overload that does not take an Evidence parameter
public:
virtual System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly, cli::array <System::Byte> ^ rawSymbolStore, System::Security::Policy::Evidence ^ securityEvidence);
public:
System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly, cli::array <System::Byte> ^ rawSymbolStore, System::Security::Policy::Evidence ^ securityEvidence);
public System.Reflection.Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore, System.Security.Policy.Evidence securityEvidence);
[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);
[System.Obsolete("Use an overload that does not take an Evidence parameter")]
public System.Reflection.Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore, System.Security.Policy.Evidence securityEvidence);
abstract member Load : byte[] * byte[] * System.Security.Policy.Evidence -> System.Reflection.Assembly
override this.Load : byte[] * byte[] * System.Security.Policy.Evidence -> System.Reflection.Assembly
[<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.")>]
abstract member Load : byte[] * byte[] * System.Security.Policy.Evidence -> System.Reflection.Assembly
override this.Load : byte[] * byte[] * System.Security.Policy.Evidence -> System.Reflection.Assembly
[<System.Obsolete("Use an overload that does not take an Evidence parameter")>]
member this.Load : byte[] * byte[] * System.Security.Policy.Evidence -> System.Reflection.Assembly
[<System.Obsolete("Use an overload that does not take an Evidence parameter")>]
abstract member Load : byte[] * byte[] * System.Security.Policy.Evidence -> System.Reflection.Assembly
override 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 for loading the assembly.
返回
加载的程序集。The loaded assembly.
实现
- 属性
例外
rawAssembly
为 null
。rawAssembly
is null
.
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
不是 null
。securityEvidence
is not null
. 未启用旧版 CAS 策略时,securityEvidence
应为 null
。When 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 开始,使用此方法加载的程序集的信任级别与应用程序域的信任级别相同。Beginning with the .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.