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:

  • 使用LoadEvidence带参数的方法时, 将使用加载程序提供的证据加载程序集。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.

    备注

    在不带 SP1 的 .NET Framework 版本1.0 和版本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和从调用程序集继承Hash而来,并且从COFF程序集获取。StrongName Url SiteZone, 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++可执行文件进行BadImageFormatException反射可能会引发。Reflecting 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.

如果对同一程序集]调用 [<, Byte x:% 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:

  • 使用LoadEvidence带参数的方法时, 将使用加载程序提供的证据加载程序集。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.

    备注

    在不带 SP1 的 .NET Framework 版本1.0 和版本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和从调用程序集继承Hash而来,并且从COFF程序集获取。StrongName Url SiteZone, 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++可执行文件进行BadImageFormatException反射可能会引发。Reflecting 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. 属性不提供程序集标识的任何元素 (如名称或版本), 因此, 不会按照按标识规则加载规则进行加载, 这与Load方法一样。 CodeBaseThe 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. 有关使用加载源上下文的缺点的信息, 请参阅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:

  • 使用LoadEvidence带参数的方法时, 将使用加载程序提供的证据加载程序集。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.

    备注

    在不带 SP1 的 .NET Framework 版本1.0 和版本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和从调用程序集继承Hash而来,并且从COFF程序集获取。StrongName Url SiteZone, 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++可执行文件进行BadImageFormatException反射可能会引发。Reflecting 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. 关联的枚举Read:PathDiscoveryAssociated 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++可执行文件进行BadImageFormatException反射可能会引发。Reflecting 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 程序集的 "System") 及其版本、区域性、公钥标记, 还可以是其处理器体系结构。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 的系统 .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:

  • 使用LoadEvidence带参数的方法时, 将使用加载程序提供的证据加载程序集。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.

    备注

    在不带 SP1 的 .NET Framework 版本1.0 和版本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和从调用程序集继承Hash而来,并且从COFF程序集获取。StrongName Url SiteZone, 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++可执行文件进行BadImageFormatException反射可能会引发。Reflecting 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. 属性不提供程序集标识的任何元素 (如名称或版本), 因此, 不会按照按标识规则加载规则进行加载, 这与Load方法一样。 CodeBaseThe 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. 有关使用加载源上下文的缺点的信息, 请参阅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:

  • 使用LoadEvidence带参数的方法时, 将使用加载程序提供的证据加载程序集。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.

    备注

    在不带 SP1 的 .NET Framework 版本1.0 和版本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和从调用程序集继承Hash而来,并且从COFF程序集获取。StrongName Url SiteZone, 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++可执行文件进行BadImageFormatException反射可能会引发。Reflecting 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. 关联的枚举Read:PathDiscoveryAssociated 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++可执行文件进行BadImageFormatException反射可能会引发。Reflecting 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.

适用于