Assembly.Load Assembly.Load Assembly.Load Assembly.Load Method

定义

加载程序集。Loads an assembly.

重载

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

加载带有基于通用对象文件格式 (COFF) 的映像的程序集,此映像包含一个已发出的程序集,并且还可选择包括符号和指定安全上下文的源。Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly, optionally including symbols and specifying the source for the security context. 此程序集将会加载到调用方的应用程序域中。The assembly is loaded into the application domain of the caller.

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

加载带有基于通用对象文件格式 (COFF) 的映像的程序集,此映像包含一个已发出的程序集,并且还可选择包括程序集的符号和证据。Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly, optionally including symbols and evidence for the assembly. 此程序集将会加载到调用方的应用程序域中。The assembly is loaded into the application domain of the caller.

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

通过给定的程序集的显示名称来加载程序集,使用提供的证据将程序集加载到调用方的域中。Loads an assembly given its display name, loading the assembly into the domain of the caller using the supplied evidence.

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

在给定程序集的 AssemblyName 的情况下,加载程序集。Loads an assembly given its AssemblyName. 使用提供的证据将该程序集加载到调用方的域中。The assembly is loaded into the domain of the caller using the supplied evidence.

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

加载带有基于通用对象文件格式 (COFF) 的映像的程序集,该映像包含已发出的程序集。Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly. 此程序集将会加载到调用方的应用程序域中。The assembly is loaded into the application domain of the caller.

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

通过给定程序集的长格式名称加载程序集。Loads an assembly given the long form of its name.

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

在给定程序集的 AssemblyName 的情况下,加载程序集。Loads an assembly given its AssemblyName.

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

加载带有基于通用对象文件格式 (COFF) 的映像的程序集,此映像包含一个已发出的程序集,并且还可以选择包括程序集的符号。Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly, optionally including symbols for the assembly. 此程序集将会加载到调用方的应用程序域中。The assembly is loaded into the application domain of the caller.

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

加载带有基于通用对象文件格式 (COFF) 的映像的程序集,此映像包含一个已发出的程序集,并且还可选择包括符号和指定安全上下文的源。Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly, optionally including symbols and specifying the source for the security context. 此程序集将会加载到调用方的应用程序域中。The assembly is loaded into the application domain of the caller.

public:
 static System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly, cli::array <System::Byte> ^ rawSymbolStore, System::Security::SecurityContextSource securityContextSource);
public static System.Reflection.Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore, System.Security.SecurityContextSource securityContextSource);
static member Load : byte[] * byte[] * System.Security.SecurityContextSource -> System.Reflection.Assembly

参数

rawAssembly
Byte[]

字节数组,它是包含已发出程序集的基于 COFF 的映像。A byte array that is a COFF-based image containing an emitted assembly.

rawSymbolStore
Byte[]

包含表示程序集符号的原始字节的字节数组。A byte array that contains the raw bytes representing the symbols for the assembly.

securityContextSource
SecurityContextSource SecurityContextSource SecurityContextSource SecurityContextSource

安全上下文的源。The source of the security context.

返回

加载的程序集。The loaded assembly.

异常

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

- 或 --or- rawAssembly 使用高于当前所加载版本的公共语言运行时版本编译而成。rawAssembly was compiled with a later version of the common language runtime than the version that is currently loaded.

securityContextSource 的值不是枚举值之一。The value of securityContextSource is not one of the enumeration values.

注解

程序集被加载到调用方的安全上下文中使用指定的源的应用程序域。The assembly is loaded into the application domain of the caller using the specified source for the security context. 如果rawSymbolStore已指定,还加载表示程序集符号的原始字节。If rawSymbolStore was specified, the raw bytes that represent the symbols for the assembly are also loaded.

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

警告

此 API 现已过时。

加载带有基于通用对象文件格式 (COFF) 的映像的程序集,此映像包含一个已发出的程序集,并且还可选择包括程序集的符号和证据。Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly, optionally including symbols and evidence for the assembly. 此程序集将会加载到调用方的应用程序域中。The assembly is loaded into the application domain of the caller.

public:
 static System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly, cli::array <System::Byte> ^ rawSymbolStore, System::Security::Policy::Evidence ^ securityEvidence);
[System.Obsolete]
[System.Obsolete("This method is 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 static System.Reflection.Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore, System.Security.Policy.Evidence securityEvidence);
static member Load : byte[] * byte[] * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Shared Function Load (rawAssembly As Byte(), rawSymbolStore As Byte(), securityEvidence As Evidence) As Assembly

参数

rawAssembly
Byte[]

字节数组,它是包含已发出程序集的基于 COFF 的映像。A byte array that is a COFF-based image containing an emitted assembly.

rawSymbolStore
Byte[]

包含表示程序集符号的原始字节的字节数组。A byte array that contains 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.

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

securityEvidence 不是 nullsecurityEvidence is not null. 默认情况下,.NET Framework 4.NET Framework 4 中未启用旧版 CAS 策略;如果未启用,则 securityEvidence 必须为 nullBy default, legacy CAS policy is not enabled in the .NET Framework 4.NET Framework 4; when it is not enabled, securityEvidence must be null.

注解

使用提供的证据将该程序集加载到调用方的域中。The assembly is loaded into the domain of the caller using the supplied evidence. 此外加载表示程序集符号的原始字节。The raw bytes representing the symbols for the assembly are also loaded.

是否将特定的权限授予程序集是基于证据的。Whether certain permissions are granted or not granted to an assembly is based on evidence. 程序集和安全证据的合并的规则如下所示:The rules for assembly and security evidence merging are as follows:

  • 当你使用Load方法没有Evidence参数,则加载程序提供的证据加载程序集。When you use a Load method with no Evidence parameter, the assembly is loaded with the evidence that the loader supplies.

  • 当你使用Load方法替换Evidence参数,证据进行合并。When you use a Load method with an Evidence parameter, pieces of evidence are merged. 作为参数提供的证据Load方法取代加载程序提供的证据。Pieces of evidence supplied as an argument to the Load method supersede pieces of evidence supplied by the loader.

  • 当你使用Load方法的重载Byte[]参数加载 COFF 映像,证据继承自调用程序集。When you use a Load method overload with a Byte[] parameter to load a COFF image, evidence is inherited from the calling assembly. 这适用于.NET Framework 1.1 版 Service Pack 1 (SP1) 和后续版本。This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    备注

    在.NET Framework 1.0 版和没有 SP1,当您使用的版本 1.1 中Load方法的重载Byte[]参数加载 COFF 映像,证据结合使用。In the .NET Framework version 1.0 and in version 1.1 without SP1, when you use a Load method overload with a Byte[] parameter to load a COFF image, evidence is combined. Zone``UrlSite继承自调用程序集,并HashStrongName取自 COFF 程序集。Zone, Url and Site are inherited from the calling assembly, and Hash and StrongName are taken from the COFF assembly.

  • 当你使用Load方法替换Byte[]参数和Evidence若要加载的 COFF 映像,请使用提供的证据。When you use a Load method with a Byte[] parameter and Evidence to load a COFF image, only the supplied evidence is used. 忽略调用程序集的证据和 COFF 映像的证据。Evidence of the calling assembly and evidence of the COFF image are ignored.

专用于反映将C++可执行文件可能会引发BadImageFormatExceptionReflecting on C++ executable files might throw a BadImageFormatException. 这是最有可能引起的C++编译器剥离重定位地址或.reloc可执行文件中的部分。This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. 若要保留.reloc地址在C++可执行文件,则指定/fixed:no在链接时。To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

如果调用 [],字节<xref:System.Reflection.Assembly.Load%2A > 方法比一次在同一个程序集,但指定不同的证据,公共语言运行时不会引发更多FileLoadException因为不能确定相等性和不同的证据规范的完整性。If you call the [], Byte<xref:System.Reflection.Assembly.Load%2A> method more than once on the same assembly but with a different evidence specified, the common language runtime does not throw a FileLoadException because the equality and integrity of the different evidence specifications cannot be determined. 第一个成功的证据为使用的证据。The evidence that first succeeds is the evidence that is used.

请注意,此方法的重载始终创建一个新Assembly具有其自己的映射对象。Note that this method overload always creates a new Assembly object with its own mapping.

安全性

SecurityPermission
它能够提供证据。for the ability to supply evidence. 关联枚举:ControlEvidenceAssociated enumeration: ControlEvidence. 安全操作: DemandSecurity action: Demand.

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

警告

此 API 现已过时。

通过给定的程序集的显示名称来加载程序集,使用提供的证据将程序集加载到调用方的域中。Loads an assembly given its display name, loading the assembly into the domain of the caller using the supplied evidence.

public:
 static System::Reflection::Assembly ^ Load(System::String ^ assemblyString, System::Security::Policy::Evidence ^ assemblySecurity);
[System.Obsolete]
[System.Obsolete("This method is 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 static System.Reflection.Assembly Load (string assemblyString, System.Security.Policy.Evidence assemblySecurity);
static member Load : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Shared Function Load (assemblyString As String, assemblySecurity As Evidence) As Assembly

参数

assemblyString
String String String String

程序集的显示名称。The display name of the assembly.

assemblySecurity
Evidence Evidence Evidence Evidence

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

返回

加载的程序集。The loaded assembly.

异常

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.

无法加载已找到的文件。A file that was found could not be loaded.

- 或 --or-

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

注解

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

是否将特定的权限授予程序集是基于证据的。Whether certain permissions are granted or not granted to an assembly is based on evidence. 程序集和安全证据的合并的规则如下所示:The rules for assembly and security evidence merging are as follows:

  • 当你使用Load方法没有Evidence参数,则加载程序提供的证据加载程序集。When you use a Load method with no Evidence parameter, the assembly is loaded with the evidence that the loader supplies.

  • 当你使用Load方法替换Evidence参数,证据进行合并。When you use a Load method with an Evidence parameter, pieces of evidence are merged. 作为参数提供的证据Load方法取代加载程序提供的证据。Pieces of evidence supplied as an argument to the Load method supersede pieces of evidence supplied by the loader.

  • 当你使用Load方法的重载Byte[]参数加载通用对象文件格式 (COFF) 图像,证据继承自调用程序集。When you use a Load method overload with a Byte[] parameter to load a common object file format (COFF) image, evidence is inherited from the calling assembly. 这适用于.NET Framework 1.1 版 Service Pack 1 (SP1) 和后续版本。This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    备注

    在.NET Framework 1.0 版和没有 SP1,当您使用的版本 1.1 中Load方法的重载Byte[]参数加载 COFF 映像,证据结合使用。In the .NET Framework version 1.0 and in version 1.1 without SP1, when you use a Load method overload with a Byte[] parameter to load a COFF image, evidence is combined. Zone``UrlSite继承自调用程序集,并HashStrongName取自 COFF 程序集。Zone, Url and Site are inherited from the calling assembly, and Hash and StrongName are taken from the COFF assembly.

  • 当你使用Load方法替换Byte[]参数和Evidence若要加载的 COFF 映像,请使用提供的证据。When you use a Load method with a Byte[] parameter and Evidence to load a COFF image, only the supplied evidence is used. 将忽略的调用程序集和 COFF 映像的证据。Evidence of the calling assembly and evidence of the COFF image is ignored.

专用于反映将C++可执行文件可能会引发BadImageFormatExceptionReflecting on C++ executable files might throw a BadImageFormatException. 这是最有可能引起的C++编译器剥离重定位地址或.reloc可执行文件中的部分。This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. 若要保留.reloc地址在C++可执行文件,则指定/fixed:no在链接时。To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

如果在同一程序集,但指定不同的证据不止一次调用此方法,公共语言运行时不会引发FileLoadException由于不能确定相等性和不同的证据规范的完整性。If you call this method more than once on the same assembly but with a different evidence specified, the common language runtime does not throw a FileLoadException because the equality and integrity of the different evidence specifications cannot be determined. 第一个成功的证据为使用的证据。The evidence that first succeeds is the evidence that is used.

在.NET Framework 2.0 版中,处理器体系结构添加到程序集标识,并可以指定为程序集名称字符串的一部分。In the .NET Framework version 2.0, processor architecture is added to assembly identity, and can be specified as part of assembly name strings. 例如,"ProcessorArchitecture = msil"。For example, "ProcessorArchitecture=msil". 但是,指定程序集名称的建议的方法是创建AssemblyName对象,并将其传递给适当的重载Load方法。However, the recommended way to specify an assembly name is to create an AssemblyName object and pass it to an appropriate overload of the Load method. 请参阅 AssemblyName.ProcessorArchitectureSee AssemblyName.ProcessorArchitecture.

安全性

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

另请参阅

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

警告

此 API 现已过时。

在给定程序集的 AssemblyName 的情况下,加载程序集。Loads an assembly given its AssemblyName. 使用提供的证据将该程序集加载到调用方的域中。The assembly is loaded into the domain of the caller using the supplied evidence.

public:
 static System::Reflection::Assembly ^ Load(System::Reflection::AssemblyName ^ assemblyRef, System::Security::Policy::Evidence ^ assemblySecurity);
[System.Obsolete]
[System.Obsolete("This method is 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 static System.Reflection.Assembly Load (System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity);
static member Load : System.Reflection.AssemblyName * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Shared Function Load (assemblyRef As AssemblyName, assemblySecurity As Evidence) As Assembly

参数

assemblyRef
AssemblyName AssemblyName AssemblyName AssemblyName

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

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.

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

- 或 --or-

assemblyRef 指定远程程序集,但在远程程序集中执行代码的功能已禁用。assemblyRef specifies a remote assembly, but the ability to execute code in remote assemblies is disabled. 请参阅 <loadFromRemoteSources>See <loadFromRemoteSources>.

注解

FileLoadException 如果引发assemblyRef指定完整的程序集名称和匹配的简单名称的第一个程序集具有不同的版本、 区域性或公钥标记。FileLoadException is thrown if assemblyRef specifies the full assembly name, and the first assembly that matches the simple name has a different version, culture, or public key token. 加载程序不会继续探测的其他程序集的简单名称相匹配。The loader does not continue probing for other assemblies that match the simple name. 从.NET Framework 4 开始,因为默认情况下,禁用远程程序集中的代码执行FileLoadException也会引发如果assemblyRef指定远程程序集。Starting with .NET Framework 4, because execution of code in remote assemblies is disabled by default, a FileLoadException is also thrown if assemblyRef specifies a remote assembly. 若要启用从远程位置加载的代码的执行,可以使用 <loadFromRemoteSources> 配置元素。To enable execution of code loaded from remote locations, you can use the <loadFromRemoteSources> configuration element.

备注

不要使用AssemblyName仅含CodeBase属性集。Do not use an AssemblyName with only the CodeBase property set. CodeBase属性不提供任何元素 (如名称或版本) 的程序集标识,因此加载不会发生根据负载通过标识规则,正如您期望从Load方法。The CodeBase property does not supply any elements of the assembly identity (such as name or version), so loading does not occur according to load-by-identity rules, as you would expect from the Load method. 相反,使用负载从规则加载程序集。Instead, the assembly is loaded using load-from rules. 使用 load-from 上下文的缺点的信息,请参阅Assembly.LoadFrom方法重载或程序集加载的最佳实践For information about the disadvantages of using the load-from context, see the Assembly.LoadFrom method overload or Best Practices for Assembly Loading.

是否将特定的权限授予程序集是基于证据的。Whether certain permissions are granted or not granted to an assembly is based on evidence. 程序集和安全证据的合并的规则如下所示:The rules for assembly and security evidence merging are as follows:

  • 当你使用Load方法没有Evidence参数,则加载程序提供的证据加载程序集。When you use a Load method with no Evidence parameter, the assembly is loaded with the evidence that the loader supplies.

  • 当你使用Load方法替换Evidence参数,证据进行合并。When you use a Load method with an Evidence parameter, pieces of evidence are merged. 作为参数提供的证据Load方法取代加载程序提供的证据。Pieces of evidence supplied as an argument to the Load method supersede pieces of evidence supplied by the loader.

  • 当你使用Load方法的重载Byte[]参数加载通用对象文件格式 (COFF) 图像,证据继承自调用程序集。When you use a Load method overload with a Byte[] parameter to load a common object file format (COFF) image, evidence is inherited from the calling assembly. 这适用于.NET Framework 1.1 版 Service Pack 1 (SP1) 和后续版本。This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    备注

    在.NET Framework 1.0 版和没有 SP1,当您使用的版本 1.1 中Load方法的重载Byte[]参数加载 COFF 映像,证据结合使用。In the .NET Framework version 1.0 and in version 1.1 without SP1, when you use a Load method overload with a Byte[] parameter to load a COFF image, evidence is combined. Zone``UrlSite继承自调用程序集,并HashStrongName取自 COFF 程序集。Zone, Url and Site are inherited from the calling assembly, and Hash and StrongName are taken from the COFF assembly.

  • 当你使用Load方法替换Byte[]参数和Evidence若要加载的 COFF 映像,请使用提供的证据。When you use a Load method with a Byte[] parameter and Evidence to load a COFF image, only the supplied evidence is used. 将忽略的调用程序集和 COFF 映像的证据。Evidence of the calling assembly and evidence of the COFF image is ignored.

专用于反映将C++可执行文件可能会引发BadImageFormatExceptionReflecting on C++ executable files might throw a BadImageFormatException. 这是最有可能引起的C++编译器剥离重定位地址或.reloc可执行文件中的部分。This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. 若要保留.reloc地址在C++可执行文件,则指定/fixed:no在链接时。To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

备注

如果这两个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, CodeBase 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方法不是一次在同一个程序集,但指定不同的证据,公共语言运行时不会引发更多FileLoadException因为相等性和完整性不同的证据规范不能为确定。If you call the Load method more than once on the same assembly but with a different evidence specified, the common language runtime does not throw a FileLoadException because the equality and integrity of the different evidence specifications cannot be determined. 第一个成功的证据为使用的证据。The evidence that first succeeds is the evidence that is used.

安全性

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

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

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

另请参阅

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

加载带有基于通用对象文件格式 (COFF) 的映像的程序集,该映像包含已发出的程序集。Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly. 此程序集将会加载到调用方的应用程序域中。The assembly is loaded into the application domain of the caller.

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

参数

rawAssembly
Byte[]

字节数组,它是包含已发出程序集的基于 COFF 的映像。A byte array 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 trust level of an assembly that is loaded by using this method is the same as the trust level of the calling assembly. 若要从应用程序域的信任级别的字节数组加载程序集,请使用Load(Byte[], Byte[], SecurityContextSource)方法重载。To load an assembly from a byte array with the trust level of the application domain, use the Load(Byte[], Byte[], SecurityContextSource) method overload. 详细了解使用的证据的重载Load方法采用字节数组,请参阅Load(Byte[], Byte[], Evidence)方法重载。For more information about the use of evidence with overloads of the Load method that take byte arrays, see the Load(Byte[], Byte[], Evidence) method overload.

专用于反映将C++可执行文件可能会引发BadImageFormatExceptionReflecting on C++ executable files might throw a BadImageFormatException. 这是最有可能引起的C++编译器剥离重定位地址或.reloc可执行文件中的部分。This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. 若要保留.reloc地址在C++可执行文件,则指定/fixed:no在链接时。To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

请注意,此方法的重载始终创建一个新Assembly具有其自己的映射对象。Note that this method overload always creates a new Assembly object with its own mapping.

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

通过给定程序集的长格式名称加载程序集。Loads an assembly given the long form of its name.

public:
 static System::Reflection::Assembly ^ Load(System::String ^ assemblyString);
public static System.Reflection.Assembly Load (string assemblyString);
static member Load : string -> System.Reflection.Assembly
Public Shared Function Load (assemblyString As String) As Assembly

参数

assemblyString
String String String String

程序集名称的长格式。The long form of the assembly name.

返回

加载的程序集。The loaded assembly.

异常

assemblyString 是一个长度为零的字符串。assemblyString is a zero-length string.

assemblyString 未找到。assemblyString is not found.

无法加载已找到的文件。A file that was found could not be loaded.

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 following example loads an assembly given its fully qualified name, and lists all the types contained in the specified 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::Collections;
using namespace System::Reflection;
int main()
{
    // You must supply a valid fully qualified assembly name.            
    Assembly^ SampleAssembly = Assembly::Load
        ( "SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3" );
    array<Type^>^ Types = SampleAssembly->GetTypes();
    
    // Display all the types contained in the specified assembly.
    IEnumerator^ myEnum = Types->GetEnumerator();
    Type^ oType;
    while ( myEnum->MoveNext() )
    {
        oType = safe_cast<Type^>(myEnum->Current);
        Console::WriteLine( oType->Name );
    }
}

using System;
using System.Reflection;

class Class1
{
    public static void Main()
    {
        // You must supply a valid fully qualified assembly name.            
        Assembly SampleAssembly = Assembly.Load
		    ("SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3");
        // Display all the types contained in the specified assembly.
		foreach (Type oType in SampleAssembly.GetTypes()) {
            Console.WriteLine(oType.Name);
        }
    }
}
Imports System
Imports System.Reflection

Class Class1
    Public Shared Sub Main()
		' You must supply a valid fully qualified assembly name.            
		Dim SampleAssembly As [Assembly] = _
			[Assembly].Load("SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3")
        Dim oType As Type
        ' Display all the types contained in the specified assembly.
		For Each oType In SampleAssembly.GetTypes()
			Console.WriteLine(oType.Name)
		Next oType
	End Sub	'LoadSample
End Class 'Class1

注解

程序集名称的长格式包含其简单名称 (如"系统"的 System.dll 程序集) 以及其版本、 区域性、 公钥标记和 (可选) 它的处理器体系结构。The long form of an assembly name consists of its simple name (such as "System" for the System.dll assembly) along with its version, culture, public key token, and optionally its processor architecture. 它对应于程序集的FullName属性。It corresponds to the assembly's FullName property. 下面的示例演示如何使用用于加载.NET Framework 4 的 System.dll 程序集的长名称。The following example illustrates the use of a long name to load the System.dll assembly for the .NET Framework 4.

using System;
using System.Reflection;

public class Example
{
   public static void Main()
   {
      string longName = "system, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
      Assembly assem = Assembly.Load(longName);
      if (assem == null)
         Console.WriteLine("Unable to load assembly...");
      else
         Console.WriteLine(assem.FullName);
   }
}
// The example displays the following output:
//        system, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Imports System.Reflection

Module Example
   Public Sub Main()
      Dim longName As String = "system, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
      Dim assem As Assembly = Assembly.Load(longName)
      If assem Is Nothing Then
         Console.WriteLine("Unable to load assembly...")
      Else
         Console.WriteLine(assem.FullName)
      End If
   End Sub
End Module
' The example displays the following output:
'       system, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

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

是否将特定的权限授予程序集是基于证据的。Whether certain permissions are granted or not granted to an assembly is based on evidence. 程序集和安全证据的合并的规则如下所示:The rules for assembly and security evidence merging are as follows:

  • 当你使用Load方法没有Evidence参数,则加载程序提供的证据加载程序集。When you use a Load method with no Evidence parameter, the assembly is loaded with the evidence that the loader supplies.

  • 当你使用Load方法替换Evidence参数,证据进行合并。When you use a Load method with an Evidence parameter, pieces of evidence are merged. 作为参数提供的证据Load方法取代加载程序提供的证据。Pieces of evidence supplied as an argument to the Load method supersede pieces of evidence supplied by the loader.

  • 当你使用Load方法的重载Byte[]参数加载通用对象文件格式 (COFF) 图像,证据继承自调用程序集。When you use a Load method overload with a Byte[] parameter to load a common object file format (COFF) image, evidence is inherited from the calling assembly. 这适用于.NET Framework 1.1 版 Service Pack 1 (SP1) 和后续版本。This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    备注

    在.NET Framework 1.0 版和没有 SP1,当您使用的版本 1.1 中Load方法的重载Byte[]参数加载 COFF 映像,证据结合使用。In the .NET Framework version 1.0 and in version 1.1 without SP1, when you use a Load method overload with a Byte[] parameter to load a COFF image, evidence is combined. Zone``UrlSite继承自调用程序集,并HashStrongName取自 COFF 程序集。Zone, Url and Site are inherited from the calling assembly, and Hash and StrongName are taken from the COFF assembly.

  • 当你使用Load方法替换Byte[]参数和Evidence若要加载的 COFF 映像,请使用提供的证据。When you use a Load method with a Byte[] parameter and Evidence to load a COFF image, only the supplied evidence is used. 将忽略的调用程序集和 COFF 映像的证据。Evidence of the calling assembly and evidence of the COFF image is ignored.

专用于反映将C++可执行文件可能会引发BadImageFormatExceptionReflecting on C++ executable files might throw a BadImageFormatException. 这是最有可能引起的C++编译器剥离重定位地址或.reloc可执行文件中的部分。This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. 若要保留.reloc地址在C++可执行文件,则指定/fixed:no在链接时。To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

在.NET Framework 2.0 版中,处理器体系结构添加到程序集标识,并可以指定为程序集名称字符串的一部分。In the .NET Framework version 2.0, processor architecture is added to assembly identity, and can be specified as part of assembly name strings. 例如,"ProcessorArchitecture = msil"。For example, "ProcessorArchitecture=msil". 但是,指定程序集名称的建议的方法是创建AssemblyName对象,并将其传递给适当的重载Load方法。However, the recommended way to specify an assembly name is to create an AssemblyName object and pass it to an appropriate overload of the Load method. 请参阅 AssemblyName.ProcessorArchitectureSee AssemblyName.ProcessorArchitecture.

安全性

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

另请参阅

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

在给定程序集的 AssemblyName 的情况下,加载程序集。Loads an assembly given its AssemblyName.

public:
 static System::Reflection::Assembly ^ Load(System::Reflection::AssemblyName ^ assemblyRef);
public static System.Reflection.Assembly Load (System.Reflection.AssemblyName assemblyRef);
static member Load : System.Reflection.AssemblyName -> System.Reflection.Assembly
Public Shared Function Load (assemblyRef As AssemblyName) As Assembly

参数

assemblyRef
AssemblyName AssemblyName AssemblyName AssemblyName

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

返回

加载的程序集。The loaded assembly.

异常

适用于 Windows 应用商店应用的 .NET可移植类库中,改为捕获基类异常 IOExceptionIn the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, IOException, instead.

无法加载已找到的文件。A file that was found could not be loaded.

- 或 --or-

assemblyRef 指定远程程序集,但在远程程序集中执行代码的功能已禁用。assemblyRef specifies a remote assembly, but the ability to execute code in remote assemblies is disabled. 请参阅 <loadFromRemoteSources>See <loadFromRemoteSources>.

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.

示例

下面的示例实例化AssemblyName对象并使用它来加载sysglobal.dll程序集。The following example instantiates an AssemblyName object and uses it to load the sysglobal.dll assembly. 该示例然后显示程序集的公共类型的完整名称。The example then displays the full name of the assembly's public types.

using System;
using System.Reflection;

public class Example
{
   public static void Main()
   {
      String fullName = "sysglobl, Version=4.0.0.0, Culture=neutral, " +
                        "PublicKeyToken=b03f5f7f11d50a3a, processor architecture=MSIL";
      var an = new AssemblyName(fullName);
      var assem = Assembly.Load(an);
      Console.WriteLine("Public types in assembly {0}:", assem.FullName);
      foreach (var t in assem.GetTypes())
         if (t.IsPublic)
            Console.WriteLine("   {0}", t.FullName);
   }
}
// The example displays the following output:
//   Public types in assembly sysglobl, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a:
//      System.Globalization.CultureAndRegionInfoBuilder
//      System.Globalization.CultureAndRegionModifiers
Imports System.Reflection

Module Example
   Public Sub Main()
      Dim fullName As String = "sysglobl, Version=4.0.0.0, Culture=neutral, " +
                               "PublicKeyToken=b03f5f7f11d50a3a, processor architecture=MSIL"
      Dim an As New AssemblyName(fullName)
      Dim assem As Assembly = Assembly.Load(an)
      Console.WriteLine("Public types in assembly {0}:", assem.FullName)
      For Each t As Type in assem.GetTypes()
         If t.IsPublic Then Console.WriteLine("   {0}", t.FullName)
      Next
   End Sub
End Module
' The example displays the following output:
'   Public types in assembly sysglobl, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a:
'      System.Globalization.CultureAndRegionInfoBuilder
'      System.Globalization.CultureAndRegionModifiers

注解

FileLoadException 如果引发assemblyRef指定完整的程序集名称和匹配的简单名称的第一个程序集具有不同的版本、 区域性或公钥标记。FileLoadException is thrown if assemblyRef specifies the full assembly name and the first assembly that matches the simple name has a different version, culture, or public key token. 加载程序不会继续探测的其他程序集的简单名称相匹配。The loader does not continue probing for other assemblies that match the simple name. 从.NET Framework 4 开始,因为默认情况下,禁用远程程序集中的代码执行FileLoadException也会引发如果assemblyRef指定远程程序集。Starting with .NET Framework 4, because execution of code in remote assemblies is disabled by default, a FileLoadException is also thrown if assemblyRef specifies a remote assembly. 若要启用从远程位置加载的代码的执行,可以使用 <loadFromRemoteSources> 配置元素。To enable execution of code loaded from remote locations, you can use the <loadFromRemoteSources> configuration element.

备注

不要使用AssemblyName仅含CodeBase属性集。Do not use an AssemblyName with only the CodeBase property set. CodeBase属性不提供任何元素 (如名称或版本) 的程序集标识,因此加载不会发生根据负载通过标识规则,正如您期望从Load方法。The CodeBase property does not supply any elements of the assembly identity (such as name or version), so loading does not occur according to load-by-identity rules, as you would expect from the Load method. 相反,使用负载从规则加载程序集。Instead, the assembly is loaded using load-from rules. 使用 load-from 上下文的缺点的信息,请参阅Assembly.LoadFrom方法重载或程序集加载的最佳实践For information about the disadvantages of using the load-from context, see the Assembly.LoadFrom method overload or Best Practices for Assembly Loading.

是否将特定的权限授予程序集是基于证据的。Whether certain permissions are granted or not granted to an assembly is based on evidence. 程序集和安全证据的合并的规则如下所示:The rules for assembly and security evidence merging are as follows:

  • 当你使用Load方法没有Evidence参数,则加载程序提供的证据加载程序集。When you use a Load method with no Evidence parameter, the assembly is loaded with the evidence that the loader supplies.

  • 当你使用Load方法替换Evidence参数,证据进行合并。When you use a Load method with an Evidence parameter, pieces of evidence are merged. 作为参数提供的证据Load方法取代加载程序提供的证据。Pieces of evidence supplied as an argument to the Load method supersede pieces of evidence supplied by the loader.

  • 当你使用Load方法的重载Byte[]参数加载通用对象文件格式 (COFF) 图像,证据继承自调用程序集。When you use a Load method overload with a Byte[] parameter to load a common object file format (COFF) image, evidence is inherited from the calling assembly. 这适用于.NET Framework 1.1 版 Service Pack 1 (SP1) 和后续版本。This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    备注

    在.NET Framework 1.0 版和没有 SP1,当您使用的版本 1.1 中Load方法的重载Byte[]参数加载 COFF 映像,证据结合使用。In the .NET Framework version 1.0 and in version 1.1 without SP1, when you use a Load method overload with a Byte[] parameter to load a COFF image, evidence is combined. Zone``UrlSite继承自调用程序集,并HashStrongName取自 COFF 程序集。Zone, Url and Site are inherited from the calling assembly, and Hash and StrongName are taken from the COFF assembly.

  • 当你使用Load方法替换Byte[]参数和Evidence若要加载的 COFF 映像,请使用提供的证据。When you use a Load method with a Byte[] parameter and Evidence to load a COFF image, only the supplied evidence is used. 将忽略的调用程序集和 COFF 映像的证据。Evidence of the calling assembly and evidence of the COFF image is ignored.

专用于反映将C++可执行文件可能会引发BadImageFormatExceptionReflecting on C++ executable files might throw a BadImageFormatException. 这是最有可能引起的C++编译器剥离重定位地址或.reloc可执行文件中的部分。This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. 若要保留.reloc地址在C++可执行文件,则指定/fixed:no在链接时。To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

备注

如果这两个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, CodeBase 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. 关联枚举: ReadPathDiscoveryAssociated enumerations: Read, PathDiscovery

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

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

另请参阅

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

加载带有基于通用对象文件格式 (COFF) 的映像的程序集,此映像包含一个已发出的程序集,并且还可以选择包括程序集的符号。Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly, optionally including symbols for the assembly. 此程序集将会加载到调用方的应用程序域中。The assembly is loaded into the application domain of the caller.

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

参数

rawAssembly
Byte[]

字节数组,它是包含已发出程序集的基于 COFF 的映像。A byte array that is a COFF-based image containing an emitted assembly.

rawSymbolStore
Byte[]

包含表示程序集符号的原始字节的字节数组。A byte array that contains 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 trust level of an assembly that is loaded by using this method is the same as the trust level of the calling assembly. 若要从应用程序域的信任级别的字节数组加载程序集,请使用Load(Byte[], Byte[], SecurityContextSource)方法重载。To load an assembly from a byte array with the trust level of the application domain, use the Load(Byte[], Byte[], SecurityContextSource) method overload. 详细了解使用的证据的重载Load方法采用字节数组,请参阅Load(Byte[], Byte[], Evidence)方法重载。For more information about the use of evidence with overloads of the Load method that take byte arrays, see the Load(Byte[], Byte[], Evidence) method overload.

专用于反映将C++可执行文件可能会引发BadImageFormatExceptionReflecting on C++ executable files might throw a BadImageFormatException. 这是最有可能引起的C++编译器剥离重定位地址或.reloc可执行文件中的部分。This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. 若要保留.reloc地址在C++可执行文件,则指定/fixed:no在链接时。To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

请注意,此方法的重载始终创建一个新Assembly具有其自己的映射对象。Note that this method overload always creates a new Assembly object with its own mapping.

适用于