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)

載入組件,指定其 AssemblyNameLoads 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[])

載入具有通用物件檔案格式 (Common Object File Format,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)

載入組件,指定其 AssemblyNameLoads 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- 目前載入的是 Common Language Runtime 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.

是否將某些使用權限授予組件則以辨識項 (Evidence) 為基礎。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. 這適用于1.1 版 Service Pack 1 (SP1)和後續版本的 .NET Framework。This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    注意

    在 .NET Framework 版本1.0 和版本1.1 (不含 SP1)中,當您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. ZoneUrl Hash StrongNameSite是繼承自呼叫元件,而和則是從 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++執行檔上反映可能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: system.object] 一次以上載入% 2a > 方法,但指定了不同的辨識項,則 common language FileLoadException runtime 不會擲回,因為無法判斷不同辨識項規格的相等和完整性。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.

例外狀況

找不到 assemblyStringassemblyString is not found.

assemblyString 不是有效的組件。assemblyString is not a valid assembly.

-或--or- 目前載入的是通用語言執行平台 2.0 版或更新版本,且已使用更新的版本來編譯 assemblyStringVersion 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.

是否將某些使用權限授予組件則以辨識項 (Evidence) 為基礎。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. 這適用于1.1 版 Service Pack 1 (SP1)和後續版本的 .NET Framework。This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    注意

    在 .NET Framework 版本1.0 和版本1.1 (不含 SP1)中,當您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. ZoneUrl Hash StrongNameSite是繼承自呼叫元件,而和則是從 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++執行檔上反映可能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.

如果您在同一個元件上多次呼叫這個方法,但是指定了不同的辨識項,common language runtime 就不會擲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 現已淘汰。

載入組件,指定其 AssemblyNameLoads 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- 目前載入的是 Common Language Runtime 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>使用 configuration 元素。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.

是否將某些使用權限授予組件則以辨識項 (Evidence) 為基礎。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. 這適用于1.1 版 Service Pack 1 (SP1)和後續版本的 .NET Framework。This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    注意

    在 .NET Framework 版本1.0 和版本1.1 (不含 SP1)中,當您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. ZoneUrl Hash StrongNameSite是繼承自呼叫元件,而和則是從 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++執行檔上反映可能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一個元件上多次呼叫方法,但指定了不同的辨識項,則 common language runtime 不會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[])

載入具有通用物件檔案格式 (Common Object File Format,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 版或更新版本,且已使用更新的版本來編譯 rawAssemblyVersion 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.

找不到 assemblyStringassemblyString is not found.

無法載入找到的檔案。A file that was found could not be loaded.

assemblyString 不是有效的組件。assemblyString is not a valid assembly.

-或--or- 目前載入的是通用語言執行平台 2.0 版或更新版本,且已使用更新的版本來編譯 assemblyStringVersion 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.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.string 元件的 "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 的 System.object 元件。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.

是否將某些使用權限授予組件則以辨識項 (Evidence) 為基礎。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. 這適用于1.1 版 Service Pack 1 (SP1)和後續版本的 .NET Framework。This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    注意

    在 .NET Framework 版本1.0 和版本1.1 (不含 SP1)中,當您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. ZoneUrl Hash StrongNameSite是繼承自呼叫元件,而和則是從 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++執行檔上反映可能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)

載入組件,指定其 AssemblyNameLoads 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 版或更新版本,且已使用更新的版本來編譯 assemblyRefVersion 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>使用 configuration 元素。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.

是否將某些使用權限授予組件則以辨識項 (Evidence) 為基礎。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. 這適用于1.1 版 Service Pack 1 (SP1)和後續版本的 .NET Framework。This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    注意

    在 .NET Framework 版本1.0 和版本1.1 (不含 SP1)中,當您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. ZoneUrl Hash StrongNameSite是繼承自呼叫元件,而和則是從 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++執行檔上反映可能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 版或更新版本,且已使用更新的版本來編譯 rawAssemblyVersion 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.

適用於