Assembly.LoadFrom Assembly.LoadFrom Assembly.LoadFrom Assembly.LoadFrom Method

定义

加载程序集。Loads an assembly.

重载

LoadFrom(String, Evidence, Byte[], AssemblyHashAlgorithm) LoadFrom(String, Evidence, Byte[], AssemblyHashAlgorithm) LoadFrom(String, Evidence, Byte[], AssemblyHashAlgorithm) LoadFrom(String, Evidence, Byte[], AssemblyHashAlgorithm)

通过给定程序集文件名或路径、安全证据、哈希值及哈希算法来加载程序集。Loads an assembly given its file name or path, security evidence, hash value, and hash algorithm.

LoadFrom(String, Byte[], AssemblyHashAlgorithm) LoadFrom(String, Byte[], AssemblyHashAlgorithm) LoadFrom(String, Byte[], AssemblyHashAlgorithm) LoadFrom(String, Byte[], AssemblyHashAlgorithm)

通过给定程序集文件名或路径、哈希值及哈希算法来加载程序集。Loads an assembly given its file name or path, hash value, and hash algorithm.

LoadFrom(String) LoadFrom(String) LoadFrom(String) LoadFrom(String)

已知程序集的文件名或路径,加载程序集。Loads an assembly given its file name or path.

LoadFrom(String, Evidence) LoadFrom(String, Evidence) LoadFrom(String, Evidence) LoadFrom(String, Evidence)

在给定程序集的文件名或路径并提供安全证据的情况下,加载程序集。Loads an assembly given its file name or path and supplying security evidence.

注解

从.NET Framework 4 开始,在从远程位置加载的程序集执行代码的功能已禁用默认情况下,在调用LoadFrom方法会抛出FileLoadExceptionStarting with .NET Framework 4, the ability to execute code in assemblies loaded from remote locations is disabled by default, and the call to the LoadFrom method throws a FileLoadException. 若要加载的程序集和执行其代码,您必须:To load the assembly and execute its code, you must either:

LoadFrom(String, Evidence, Byte[], AssemblyHashAlgorithm) LoadFrom(String, Evidence, Byte[], AssemblyHashAlgorithm) LoadFrom(String, Evidence, Byte[], AssemblyHashAlgorithm) LoadFrom(String, Evidence, Byte[], AssemblyHashAlgorithm)

警告

此 API 现已过时。

通过给定程序集文件名或路径、安全证据、哈希值及哈希算法来加载程序集。Loads an assembly given its file name or path, security evidence, hash value, and hash algorithm.

public:
 static System::Reflection::Assembly ^ LoadFrom(System::String ^ assemblyFile, System::Security::Policy::Evidence ^ securityEvidence, cli::array <System::Byte> ^ hashValue, System::Configuration::Assemblies::AssemblyHashAlgorithm hashAlgorithm);
[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 LoadFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public static System.Reflection.Assembly LoadFrom (string assemblyFile, System.Security.Policy.Evidence securityEvidence, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm);
static member LoadFrom : string * System.Security.Policy.Evidence * byte[] * System.Configuration.Assemblies.AssemblyHashAlgorithm -> System.Reflection.Assembly
Public Shared Function LoadFrom (assemblyFile As String, securityEvidence As Evidence, hashValue As Byte(), hashAlgorithm As AssemblyHashAlgorithm) As Assembly

参数

assemblyFile
String String String String

包含程序集清单的文件的名称或路径。The name or path of the file that contains the manifest of the assembly.

securityEvidence
Evidence Evidence Evidence Evidence

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

hashValue
Byte[]

计算所得的哈希代码的值。The value of the computed hash code.

hashAlgorithm
AssemblyHashAlgorithm AssemblyHashAlgorithm AssemblyHashAlgorithm AssemblyHashAlgorithm

用于对文件进行哈希处理并生成强名称的哈希算法。The hash algorithm used for hashing files and for generating the strong name.

返回

加载的程序集。The loaded assembly.

异常

未找到 assemblyFile,或者你正在试图加载的模块未指定文件名扩展。assemblyFile is not found, or the module you are trying to load does not specify a filename extension.

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

- 或 --or- securityEvidence 是明确的,但被确定为无效。The securityEvidence is not ambiguous and is determined to be invalid.

- 或 --or-

在远程程序集中执行代码的功能已禁用。The ability to execute code in remote assemblies is disabled. 请参阅 <loadFromRemoteSources>See <loadFromRemoteSources>.

assemblyFile 不是有效的程序集 ;例如 64 位进程中的 32 位程序集。assemblyFile is not a valid assembly; for example, a 32-bit assembly in a 64-bit process. 有关详细信息,请参阅异常主题。See the exception topic for more information.

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

指定了不以“file://”开头的基本代码,且没有所需的 WebPermissionA codebase that does not start with "file://" was specified without the required WebPermission.

assemblyFile 参数为空字符串 ("")。The assemblyFile parameter is an empty string ("").

程序集名称超过系统定义的最大长度。The assembly name exceeds the system-defined maximum length.

注解

assemblyFile参数必须引用不包含转义符的 URI。The assemblyFile parameter must refer to a URI without escape characters. 此方法提供的 URI 中的所有无效字符的转义符。This method supplies escape characters for all invalid characters in the URI.

备注

不支持文件传输协议 (FTP)。File transfer protocol (FTP) is not supported. 如果为 URI 提供assemblyFile是 FTP 地址,则不会加载该程序集。If the URI supplied for assemblyFile is an FTP address, the assembly is not loaded. 不引发异常。No exception is thrown.

assemblyFile 可以是绝对或相对于当前目录,并将程序集加载到调用方的域。assemblyFile may be absolute or relative to the current directory, and the assembly is loaded into the domain of the caller.

程序集可以将加载到三个上下文中的一个,也可以在没有上下文的情况下加载:Assemblies can be loaded into one of three contexts, or can be loaded without context:

  • 加载上下文包含通过探测找到的程序集: 在 gac 中,在宿主程序集存储托管运行时,或在ApplicationBasePrivateBinPath的应用程序域。The load context contains assemblies found by probing: in the GAC, in a host assembly store if the runtime is hosted, or in the ApplicationBase and PrivateBinPath of the application domain. Load 方法的大多数重载都将程序集加载到此上下文中。Most overloads of the Load method load assemblies into this context.

  • 加载位置上下文包含程序集为其用户提供了不包括在搜索通过探测的目录的路径。The load-from context contains assemblies for which the user provided a path not included in the directories searched by probing. LoadFromCreateInstanceFromExecuteAssembly 都是通过路径加载的方法的示例。LoadFrom, CreateInstanceFrom, and ExecuteAssembly are examples of methods that load by path.

    从.NET Framework 4 开始,如果的 URIassemblyFile指定远程位置,默认情况下,禁用程序集加载和LoadFrom方法会抛出FileLoadExceptionStarting with .NET Framework 4, if the URI of assemblyFile specifies a remote location, assembly loading is disabled by default, and the LoadFrom method throws a FileLoadException. 若要启用从远程位置加载的代码的执行,可以使用 <loadFromRemoteSources> 配置元素。To enable execution of code loaded from remote locations, you can use the <loadFromRemoteSources> configuration element.

  • 仅限反射上下文包含与加载的程序集ReflectionOnlyLoadReflectionOnlyLoadFrom方法; 在这些代码不能执行上下文。The reflection-only context contains assemblies loaded with the ReflectionOnlyLoad and ReflectionOnlyLoadFrom methods; code in these contexts cannot be executed.

  • 如果用户生成或找到了程序集时,它不在任何上下文中。If the user generated or found the assembly, it is not in any context. 这适用于使用重载的加载程序集Load方法指定一个字节数组,包含程序集,并使用反射创建瞬态动态程序集发出和未保存到磁盘。This applies to assemblies loaded using overloads of the Load method that specify a byte array containing an assembly, and to transient dynamic assemblies created with reflection emit and not saved to disk.

加载位置上下文允许从探测中, 未包括的路径加载程序集,但若要找出并加载,因为路径信息由上下文维护该路径上也允许使用依赖项。The load-from context allows an assembly to be loaded from a path not included in probing, and yet allows dependencies on that path to be found and loaded because the path information is maintained by the context.

LoadFrom方法具有以下缺点。The LoadFrom method has the following disadvantages. 请考虑改用 LoadConsider using Load instead.

  • 如果已加载一个具有相同标识的程序集,则即使指定了不同的路径,LoadFrom 仍返回已加载的程序集。If an assembly with the same identity is already loaded, LoadFrom returns the loaded assembly even if a different path was specified.

  • 如果程序集加载了LoadFrom,以及更高版本中的加载上下文的程序集尝试按显示名称加载同一程序集,加载尝试将失败。If an assembly is loaded with LoadFrom, and later an assembly in the load context attempts to load the same assembly by display name, the load attempt fails. 对程序集进行反序列化时,可能发生这种情况。This can occur when an assembly is deserialized.

  • 如果程序集加载了LoadFrom,并且探测路径包括具有相同标识,而另一个位置的程序集InvalidCastExceptionMissingMethodException,否则会发生其他意外的行为。If an assembly is loaded with LoadFrom, and the probing path includes an assembly with the same identity but a different location, an InvalidCastException, MissingMethodException, or other unexpected behavior can occur.

  • LoadFrom 需要对指定路径的 FileIOPermissionAccess.ReadFileIOPermissionAccess.PathDiscoveryWebPermissionLoadFrom demands FileIOPermissionAccess.Read and FileIOPermissionAccess.PathDiscovery, or WebPermission, on the specified path.

  • 如果本机映像存在assemblyFile,不使用它。If a native image exists for assemblyFile, it is not used. 无法加载为非特定域的程序集。The assembly cannot be loaded as domain neutral.

  • 在.NET Framework 1.0 和 1.1 版中,不应用策略。In the .NET Framework version 1.0 and 1.1, policy is not applied.

是否将特定的权限授予程序集是基于证据的。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:

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

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

  • 如果在同一程序集,但指定不同的证据不止一次调用此方法,公共语言运行时不会引发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.

  • 当你使用LoadFrom方法替换Byte[]参数加载通用对象文件格式 (COFF) 图像,证据结合使用。When you use a LoadFrom method with a Byte[] parameter to load a common object file format (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.

  • 当你使用LoadFrom方法替换Byte[]参数和Evidence若要加载的 COFF 映像,请使用提供的证据。When you use a LoadFrom 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.

安全性

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

FileIOPermission
用于读取以"file://"开头的 URI。for reading a URI that begins with "file://". 关联的枚举: ReadAssociated enumeration: Read

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

LoadFrom(String, Byte[], AssemblyHashAlgorithm) LoadFrom(String, Byte[], AssemblyHashAlgorithm) LoadFrom(String, Byte[], AssemblyHashAlgorithm) LoadFrom(String, Byte[], AssemblyHashAlgorithm)

通过给定程序集文件名或路径、哈希值及哈希算法来加载程序集。Loads an assembly given its file name or path, hash value, and hash algorithm.

public:
 static System::Reflection::Assembly ^ LoadFrom(System::String ^ assemblyFile, cli::array <System::Byte> ^ hashValue, System::Configuration::Assemblies::AssemblyHashAlgorithm hashAlgorithm);
public static System.Reflection.Assembly LoadFrom (string assemblyFile, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm);
static member LoadFrom : string * byte[] * System.Configuration.Assemblies.AssemblyHashAlgorithm -> System.Reflection.Assembly
Public Shared Function LoadFrom (assemblyFile As String, hashValue As Byte(), hashAlgorithm As AssemblyHashAlgorithm) As Assembly

参数

assemblyFile
String String String String

包含程序集清单的文件的名称或路径。The name or path of the file that contains the manifest of the assembly.

hashValue
Byte[]

计算所得的哈希代码的值。The value of the computed hash code.

hashAlgorithm
AssemblyHashAlgorithm AssemblyHashAlgorithm AssemblyHashAlgorithm AssemblyHashAlgorithm

用于对文件进行哈希处理并生成强名称的哈希算法。The hash algorithm used for hashing files and for generating the strong name.

返回

加载的程序集。The loaded assembly.

异常

未找到 assemblyFile,或者你正在试图加载的模块未指定文件扩展名。assemblyFile is not found, or the module you are trying to load does not specify a file name extension.

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

- 或 --or-

在远程程序集中执行代码的功能已禁用。The ability to execute code in remote assemblies is disabled. 请参阅 <loadFromRemoteSources>See <loadFromRemoteSources>.

assemblyFile 不是有效的程序集 ;例如 64 位进程中的 32 位程序集。assemblyFile is not a valid assembly; for example, a 32-bit assembly in a 64-bit process. 有关详细信息,请参阅异常主题。See the exception topic for more information.

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

指定了不以“file://”开头的基本代码,且没有所需的 WebPermissionA codebase that does not start with "file://" was specified without the required WebPermission.

assemblyFile 参数为空字符串 ("")。The assemblyFile parameter is an empty string ("").

程序集名称超过系统定义的最大长度。The assembly name exceeds the system-defined maximum length.

注解

assemblyFile参数必须引用不包含转义符的 URI。The assemblyFile parameter must refer to a URI without escape characters. 此方法提供的 URI 中的所有无效字符的转义符。This method supplies escape characters for all invalid characters in the URI.

备注

不支持文件传输协议 (FTP)。File transfer protocol (FTP) is not supported. 如果为 URI 提供assemblyFile是 FTP 地址,则不会加载该程序集。If the URI supplied for assemblyFile is an FTP address, the assembly is not loaded. 不引发异常。No exception is thrown.

assemblyFile 可以是绝对或相对于当前目录,并将程序集加载到调用方的域。assemblyFile may be absolute or relative to the current directory, and the assembly is loaded into the domain of the caller.

程序集可以将加载到三个上下文中的一个,也可以在没有上下文的情况下加载:Assemblies can be loaded into one of three contexts, or can be loaded without context:

  • 加载上下文包含通过探测找到的程序集: 在全局程序集缓存中,在宿主程序集存储托管运行时,或在ApplicationBasePrivateBinPath的应用程序域。The load context contains assemblies found by probing: in the global assembly cache, in a host assembly store if the runtime is hosted, or in the ApplicationBase and PrivateBinPath of the application domain. Load 方法的大多数重载都将程序集加载到此上下文中。Most overloads of the Load method load assemblies into this context.

  • 加载位置上下文包含程序集为其用户提供了探测中未包括的路径。The load-from context contains assemblies for which the user provided a path that is not included in probing. LoadFromCreateInstanceFromExecuteAssembly 都是通过路径加载的方法的示例。LoadFrom, CreateInstanceFrom, and ExecuteAssembly are examples of methods that load by path.

    从.NET Framework 4 开始,如果的 URIassemblyFile指定远程位置,默认情况下,禁用程序集加载和LoadFrom方法会抛出FileLoadExceptionStarting with .NET Framework 4, if the URI of assemblyFile specifies a remote location, assembly loading is disabled by default, and the LoadFrom method throws a FileLoadException. 若要启用从远程位置加载的代码的执行,可以使用 <loadFromRemoteSources> 配置元素。To enable execution of code loaded from remote locations, you can use the <loadFromRemoteSources> configuration element.

  • 仅限反射上下文包含与加载的程序集ReflectionOnlyLoadReflectionOnlyLoadFrom方法; 在这些代码不能执行上下文。The reflection-only context contains assemblies loaded with the ReflectionOnlyLoad and ReflectionOnlyLoadFrom methods; code in these contexts cannot be executed.

  • 如果用户生成或找到了程序集时,它不在任何上下文中。If the user generated or found the assembly, it is not in any context. 这适用于使用重载的加载程序集Load方法指定一个字节数组,包含程序集,并使用反射创建瞬态动态程序集发出和未保存到磁盘。This applies to assemblies loaded using overloads of the Load method that specify a byte array containing an assembly, and to transient dynamic assemblies created with reflection emit and not saved to disk.

加载位置上下文允许从探测中, 未包括的路径加载程序集,但若要找出并加载,因为路径信息由上下文维护该路径上也允许使用依赖项。The load-from context allows an assembly to be loaded from a path that is not included in probing, and yet allows dependencies on that path to be found and loaded because the path information is maintained by the context.

LoadFrom方法具有以下缺点。The LoadFrom method has the following disadvantages. 请考虑改用 LoadConsider using Load instead.

  • 如果已加载一个具有相同标识的程序集,则即使指定了不同的路径,LoadFrom 仍返回已加载的程序集。If an assembly with the same identity is already loaded, LoadFrom returns the loaded assembly even if a different path was specified.

  • 如果程序集加载了LoadFrom,以及更高版本中的加载上下文的程序集尝试按显示名称加载同一程序集,加载尝试将失败。If an assembly is loaded with LoadFrom, and later an assembly in the load context attempts to load the same assembly by display name, the load attempt fails. 对程序集进行反序列化时,可能发生这种情况。This can occur when an assembly is deserialized.

  • 如果程序集加载了LoadFrom,并且探测路径包括具有相同标识,而另一个位置的程序集InvalidCastExceptionMissingMethodException,否则会发生其他意外的行为。If an assembly is loaded with LoadFrom, and the probing path includes an assembly with the same identity but a different location, an InvalidCastException, MissingMethodException, or other unexpected behavior can occur.

  • LoadFrom 需要对指定路径的 FileIOPermissionAccess.ReadFileIOPermissionAccess.PathDiscoveryWebPermissionLoadFrom demands FileIOPermissionAccess.Read and FileIOPermissionAccess.PathDiscovery, or WebPermission, on the specified path.

  • 如果本机映像存在assemblyFile,不使用它。If a native image exists for assemblyFile, it is not used. 程序集不能以非特定于域的方式加载。The assembly cannot be loaded as domain-neutral.

程序集的加载程序提供的证据加载。The assembly is loaded with the evidence that the loader supplies.

安全性

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

FileIOPermission
用于读取以"file://"开头的 URI。for reading a URI that begins with "file://". 关联的枚举: ReadAssociated enumeration: Read

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

LoadFrom(String) LoadFrom(String) LoadFrom(String) LoadFrom(String)

已知程序集的文件名或路径,加载程序集。Loads an assembly given its file name or path.

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

参数

assemblyFile
String String String String

包含程序集清单的文件的名称或路径。The name or path of the file that contains the manifest of the assembly.

返回

加载的程序集。The loaded assembly.

异常

未找到 assemblyFile,或者你正在试图加载的模块未指定文件名扩展。assemblyFile is not found, or the module you are trying to load does not specify a filename extension.

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

- 或 --or-

在远程程序集中执行代码的功能已禁用。The ability to execute code in remote assemblies is disabled. 请参阅 <loadFromRemoteSources>See <loadFromRemoteSources>.

assemblyFile 不是有效的程序集 ;例如 64 位进程中的 32 位程序集。assemblyFile is not a valid assembly; for example, a 32-bit assembly in a 64-bit process. 有关详细信息,请参阅异常主题。See the exception topic for more information.

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

指定了不以“file://”开头的基本代码,且没有所需的 WebPermissionA codebase that does not start with "file://" was specified without the required WebPermission.

assemblyFile 参数为空字符串 ("")。The assemblyFile parameter is an empty string ("").

程序集名称超过系统定义的最大长度。The assembly name exceeds the system-defined maximum length.

示例

下面的示例加载给定的文件名或路径的程序集。The following example loads an assembly given its file name or path.

Assembly^ SampleAssembly;
SampleAssembly = Assembly::LoadFrom( "c:\\Sample.Assembly.dll" );
// Obtain a reference to a method known to exist in assembly.
MethodInfo^ Method = SampleAssembly->GetTypes()[ 0 ]->GetMethod( "Method1" );
// Obtain a reference to the parameters collection of the MethodInfo instance.
array<ParameterInfo^>^ Params = Method->GetParameters();
// Display information about method parameters.
// Param = sParam1
//   Type = System::String
//   Position = 0
//   Optional=False
for each ( ParameterInfo^ Param in Params )
{
   Console::WriteLine( "Param= {0}", Param->Name );
   Console::WriteLine( "  Type= {0}", Param->ParameterType );
   Console::WriteLine( "  Position= {0}", Param->Position );
   Console::WriteLine( "  Optional= {0}", Param->IsOptional );
}
Assembly SampleAssembly;
SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll");
// Obtain a reference to a method known to exist in assembly.
MethodInfo Method = SampleAssembly.GetTypes()[0].GetMethod("Method1");
// Obtain a reference to the parameters collection of the MethodInfo instance.
ParameterInfo[] Params = Method.GetParameters();
// Display information about method parameters.
// Param = sParam1
//   Type = System.String
//   Position = 0
//   Optional=False
foreach (ParameterInfo Param in Params)
{
    Console.WriteLine("Param=" + Param.Name.ToString());
    Console.WriteLine("  Type=" + Param.ParameterType.ToString());
    Console.WriteLine("  Position=" + Param.Position.ToString());
    Console.WriteLine("  Optional=" + Param.IsOptional.ToString());
}
Dim SampleAssembly As [Assembly]
SampleAssembly = [Assembly].LoadFrom("c:\Sample.Assembly.dll")
' Obtain a reference to a method known to exist in assembly.
Dim Method As MethodInfo = SampleAssembly.GetTypes()(0).GetMethod("Method1")
' Obtain a reference to the parameters collection of the MethodInfo instance.
Dim Params As ParameterInfo() = Method.GetParameters()
' Display information about method parameters.
' Param = sParam1
'   Type = System.String
'   Position = 0
'   Optional=False
For Each Param As ParameterInfo In Params
    Console.WriteLine(("Param=" + Param.Name.ToString()))
    Console.WriteLine(("  Type=" + Param.ParameterType.ToString()))
    Console.WriteLine(("  Position=" + Param.Position.ToString()))
    Console.WriteLine(("  Optional=" + Param.IsOptional.ToString()))
Next 

注解

assemblyFile参数必须引用不包含转义符的 URI。The assemblyFile parameter must refer to a URI without escape characters. 此方法提供的 URI 中的所有无效字符的转义符。This method supplies escape characters for all invalid characters in the URI.

备注

不支持文件传输协议 (FTP)。File transfer protocol (FTP) is not supported. 如果为 URI 提供assemblyFile是 FTP 地址,则不会加载该程序集。If the URI supplied for assemblyFile is an FTP address, the assembly is not loaded. 不引发异常。No exception is thrown.

assemblyFile 可以是绝对或相对于当前目录,并将程序集加载到调用方的域。assemblyFile may be absolute or relative to the current directory, and the assembly is loaded into the domain of the caller.

程序集可以将加载到三个上下文中的一个,也可以在没有上下文的情况下加载:Assemblies can be loaded into one of three contexts, or can be loaded without context:

  • 加载上下文包含通过探测找到的程序集: 在 gac 中,在宿主程序集存储托管运行时,或在ApplicationBasePrivateBinPath的应用程序域。The load context contains assemblies found by probing: in the GAC, in a host assembly store if the runtime is hosted, or in the ApplicationBase and PrivateBinPath of the application domain. Load 方法的大多数重载都将程序集加载到此上下文中。Most overloads of the Load method load assemblies into this context.

  • 加载位置上下文包含程序集为其用户提供了不包括在搜索通过探测的目录的路径。The load-from context contains assemblies for which the user provided a path not included in the directories searched by probing. LoadFromCreateInstanceFromExecuteAssembly 都是通过路径加载的方法的示例。LoadFrom, CreateInstanceFrom, and ExecuteAssembly are examples of methods that load by path.

    从.NET Framework 4 开始,如果的 URIassemblyFile指定远程位置,默认情况下,禁用程序集加载和LoadFrom方法会抛出FileLoadExceptionStarting with .NET Framework 4, if the URI of assemblyFile specifies a remote location, assembly loading is disabled by default, and the LoadFrom method throws a FileLoadException. 若要启用从远程位置加载的代码的执行,可以使用 <loadFromRemoteSources> 配置元素。To enable execution of code loaded from remote locations, you can use the <loadFromRemoteSources> configuration element.

  • 仅限反射上下文包含与加载的程序集ReflectionOnlyLoadReflectionOnlyLoadFrom方法; 在这些代码不能执行上下文。The reflection-only context contains assemblies loaded with the ReflectionOnlyLoad and ReflectionOnlyLoadFrom methods; code in these contexts cannot be executed.

  • 如果用户生成或找到了程序集时,它不在任何上下文中。If the user generated or found the assembly, it is not in any context. 这适用于使用重载的加载程序集Load方法指定一个字节数组,包含程序集,并使用反射创建瞬态动态程序集发出和未保存到磁盘。This applies to assemblies loaded using overloads of the Load method that specify a byte array containing an assembly, and to transient dynamic assemblies created with reflection emit and not saved to disk.

加载位置上下文允许从探测中, 未包括的路径加载程序集,但若要找出并加载,因为路径信息由上下文维护该路径上也允许使用依赖项。The load-from context allows an assembly to be loaded from a path not included in probing, and yet allows dependencies on that path to be found and loaded because the path information is maintained by the context.

LoadFrom方法具有以下缺点。The LoadFrom method has the following disadvantages. 请考虑改用 LoadConsider using Load instead.

  • 如果已加载一个具有相同标识的程序集,则即使指定了不同的路径,LoadFrom 仍返回已加载的程序集。If an assembly with the same identity is already loaded, LoadFrom returns the loaded assembly even if a different path was specified.

  • 如果程序集加载了LoadFrom,以及更高版本中的加载上下文的程序集尝试按显示名称加载同一程序集,加载尝试将失败。If an assembly is loaded with LoadFrom, and later an assembly in the load context attempts to load the same assembly by display name, the load attempt fails. 这可能执行反序列化程序集时。This can occur when an assembly is de-serialized.

  • 如果程序集加载了LoadFrom,并且探测路径包括具有相同标识,而另一个位置的程序集InvalidCastExceptionMissingMethodException,否则会发生其他意外的行为。If an assembly is loaded with LoadFrom, and the probing path includes an assembly with the same identity but a different location, an InvalidCastException, MissingMethodException, or other unexpected behavior can occur.

  • LoadFrom 需要对指定路径的 FileIOPermissionAccess.ReadFileIOPermissionAccess.PathDiscoveryWebPermissionLoadFrom demands FileIOPermissionAccess.Read and FileIOPermissionAccess.PathDiscovery, or WebPermission, on the specified path.

  • 如果本机映像存在assemblyFile,不使用它。If a native image exists for assemblyFile, it is not used. 无法加载为非特定域的程序集。The assembly cannot be loaded as domain neutral.

  • 在.NET Framework 1.0 和 1.1 版中,不应用策略。In the .NET Framework version 1.0 and 1.1, policy is not applied.

安全性

FileIOPermission
用于读取以"file://"开头的 URI。for reading a URI that begins with "file://". 关联的枚举: ReadAssociated enumeration: Read

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

LoadFrom(String, Evidence) LoadFrom(String, Evidence) LoadFrom(String, Evidence) LoadFrom(String, Evidence)

警告

此 API 现已过时。

在给定程序集的文件名或路径并提供安全证据的情况下,加载程序集。Loads an assembly given its file name or path and supplying security evidence.

public:
 static System::Reflection::Assembly ^ LoadFrom(System::String ^ assemblyFile, 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 LoadFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public static System.Reflection.Assembly LoadFrom (string assemblyFile, System.Security.Policy.Evidence securityEvidence);
static member LoadFrom : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Shared Function LoadFrom (assemblyFile As String, securityEvidence As Evidence) As Assembly

参数

assemblyFile
String String String String

包含程序集清单的文件的名称或路径。The name or path of the file that contains the manifest of the assembly.

securityEvidence
Evidence Evidence Evidence Evidence

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

返回

加载的程序集。The loaded assembly.

异常

未找到 assemblyFile,或者你正在试图加载的模块未指定文件名扩展。assemblyFile is not found, or the module you are trying to load does not specify a filename extension.

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

- 或 --or- securityEvidence 是明确的,但被确定为无效。The securityEvidence is not ambiguous and is determined to be invalid.

- 或 --or-

在远程程序集中执行代码的功能已禁用。The ability to execute code in remote assemblies is disabled. 请参阅 <loadFromRemoteSources>See <loadFromRemoteSources>.

assemblyFile 不是有效的程序集 ;例如 64 位进程中的 32 位程序集。assemblyFile is not a valid assembly; for example, a 32-bit assembly in a 64-bit process. 有关详细信息,请参阅异常主题。See the exception topic for more information.

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

指定了不以“file://”开头的基本代码,且没有所需的 WebPermissionA codebase that does not start with "file://" was specified without the required WebPermission.

assemblyFile 参数为空字符串 ("")。The assemblyFile parameter is an empty string ("").

程序集名称超过系统定义的最大长度。The assembly name exceeds the system-defined maximum length.

注解

assemblyFile参数必须引用不包含转义符的 URI。The assemblyFile parameter must refer to a URI without escape characters. 此方法提供的 URI 中的所有无效字符的转义符。This method supplies escape characters for all invalid characters in the URI.

备注

不支持文件传输协议 (FTP)。File transfer protocol (FTP) is not supported. 如果为 URI 提供assemblyFile是 FTP 地址,则不会加载该程序集。If the URI supplied for assemblyFile is an FTP address, the assembly is not loaded. 不引发异常。No exception is thrown.

assemblyFile 可以是绝对或相对于当前目录,并将程序集加载到调用方的域。assemblyFile may be absolute or relative to the current directory, and the assembly is loaded into the domain of the caller.

程序集可以将加载到三个上下文中的一个,也可以在没有上下文的情况下加载:Assemblies can be loaded into one of three contexts, or can be loaded without context:

  • 加载上下文包含通过探测找到的程序集: 在 gac 中,在宿主程序集存储托管运行时,或在ApplicationBasePrivateBinPath的应用程序域。The load context contains assemblies found by probing: in the GAC, in a host assembly store if the runtime is hosted, or in the ApplicationBase and PrivateBinPath of the application domain. Load 方法的大多数重载都将程序集加载到此上下文中。Most overloads of the Load method load assemblies into this context.

  • 加载位置上下文包含程序集为其用户提供了不包括在搜索通过探测的目录的路径。The load-from context contains assemblies for which the user provided a path not included in the directories searched by probing. LoadFromCreateInstanceFromExecuteAssembly 都是通过路径加载的方法的示例。LoadFrom, CreateInstanceFrom, and ExecuteAssembly are examples of methods that load by path.

    从.NET Framework 4 开始,如果的 URIassemblyFile指定远程位置,默认情况下,禁用程序集加载和LoadFrom方法会抛出FileLoadExceptionStarting with .NET Framework 4, if the URI of assemblyFile specifies a remote location, assembly loading is disabled by default, and the LoadFrom method throws a FileLoadException. 若要启用从远程位置加载的代码的执行,可以使用 <loadFromRemoteSources> 配置元素。To enable execution of code loaded from remote locations, you can use the <loadFromRemoteSources> configuration element.

  • 仅限反射上下文包含与加载的程序集ReflectionOnlyLoadReflectionOnlyLoadFrom方法; 在这些代码不能执行上下文。The reflection-only context contains assemblies loaded with the ReflectionOnlyLoad and ReflectionOnlyLoadFrom methods; code in these contexts cannot be executed.

  • 如果用户生成或找到了程序集时,它不在任何上下文中。If the user generated or found the assembly, it is not in any context. 这适用于使用重载的加载程序集Load方法指定一个字节数组,包含程序集,并使用反射创建瞬态动态程序集发出和未保存到磁盘。This applies to assemblies loaded using overloads of the Load method that specify a byte array containing an assembly, and to transient dynamic assemblies created with reflection emit and not saved to disk.

加载位置上下文允许从探测中, 未包括的路径加载程序集,但若要找出并加载,因为路径信息由上下文维护该路径上也允许使用依赖项。The load-from context allows an assembly to be loaded from a path not included in probing, and yet allows dependencies on that path to be found and loaded because the path information is maintained by the context.

LoadFrom方法具有以下缺点。The LoadFrom method has the following disadvantages. 请考虑改用 LoadConsider using Load instead.

  • 如果已加载一个具有相同标识的程序集,则即使指定了不同的路径,LoadFrom 仍返回已加载的程序集。If an assembly with the same identity is already loaded, LoadFrom returns the loaded assembly even if a different path was specified.

  • 如果程序集加载了LoadFrom,以及更高版本中的加载上下文的程序集尝试按显示名称加载同一程序集,加载尝试将失败。If an assembly is loaded with LoadFrom, and later an assembly in the load context attempts to load the same assembly by display name, the load attempt fails. 对程序集进行反序列化时,可能发生这种情况。This can occur when an assembly is deserialized.

  • 如果程序集加载了LoadFrom,并且探测路径包括具有相同标识,而另一个位置的程序集InvalidCastExceptionMissingMethodException,否则会发生其他意外的行为。If an assembly is loaded with LoadFrom, and the probing path includes an assembly with the same identity but a different location, an InvalidCastException, MissingMethodException, or other unexpected behavior can occur.

  • LoadFrom 需要对指定路径的 FileIOPermissionAccess.ReadFileIOPermissionAccess.PathDiscoveryWebPermissionLoadFrom demands FileIOPermissionAccess.Read and FileIOPermissionAccess.PathDiscovery, or WebPermission, on the specified path.

  • 如果本机映像存在assemblyFile,不使用它。If a native image exists for assemblyFile, it is not used. 无法加载为非特定域的程序集。The assembly cannot be loaded as domain neutral.

  • 在.NET Framework 1.0 和 1.1 版中,不应用策略。In the .NET Framework version 1.0 and 1.1, policy is not applied.

是否将特定的权限授予程序集是基于证据的。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:

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

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

  • 如果在同一程序集,但指定不同的证据不止一次调用此方法,公共语言运行时不会引发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.

  • 当你使用LoadFrom方法替换Byte[]参数加载通用对象文件格式 (COFF) 图像,证据结合使用。When you use a LoadFrom method with a Byte[] parameter to load a common object file format (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.

  • 当你使用LoadFrom方法替换Byte[]参数和Evidence若要加载的 COFF 映像,请使用提供的证据。When you use a LoadFrom 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.

安全性

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

FileIOPermission
用于读取以"file://"开头的 URI。for reading a URI that begins with "file://". 关联的枚举: ReadAssociated enumeration: Read

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

另请参阅

适用于