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方法的调用将FileLoadException引发。Starting 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. 如果为提供的assemblyFile URI 是 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 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 开始, 如果的 URI assemblyFile指定远程位置, 则默认情况下将禁用程序集加载, 并且该LoadFrom方法将FileLoadException引发。Starting 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加载程序集, 并且探测路径包含具有相同标识但位置不同的程序集InvalidCastException, 则可能会出现、 MissingMethodException或其他意外行为。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:

  • 使用LoadFromEvidence带参数的方法时, 将使用加载程序提供的证据加载程序集。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和从调用程序集继承Hash而来,并且从COFF程序集获取。StrongName Url SiteZone, 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. 如果为提供的assemblyFile URI 是 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:

  • 加载上下文包含探测发现的程序集: 在全局程序集缓存中, 如果承载运行时, 则在主机程序集存储区中ApplicationBase , PrivateBinPath或者在应用程序域的和中。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 开始, 如果的 URI assemblyFile指定远程位置, 则默认情况下将禁用程序集加载, 并且该LoadFrom方法将FileLoadException引发。Starting 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加载程序集, 并且探测路径包含具有相同标识但位置不同的程序集InvalidCastException, 则可能会出现、 MissingMethodException或其他意外行为。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. 如果为提供的assemblyFile URI 是 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 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 开始, 如果的 URI assemblyFile指定远程位置, 则默认情况下将禁用程序集加载, 并且该LoadFrom方法将FileLoadException引发。Starting 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加载程序集, 并且探测路径包含具有相同标识但位置不同的程序集InvalidCastException, 则可能会出现、 MissingMethodException或其他意外行为。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. 如果为提供的assemblyFile URI 是 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 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 开始, 如果的 URI assemblyFile指定远程位置, 则默认情况下将禁用程序集加载, 并且该LoadFrom方法将FileLoadException引发。Starting 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加载程序集, 并且探测路径包含具有相同标识但位置不同的程序集InvalidCastException, 则可能会出现、 MissingMethodException或其他意外行为。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:

  • 使用LoadFromEvidence带参数的方法时, 将使用加载程序提供的证据加载程序集。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和从调用程序集继承Hash而来,并且从COFF程序集获取。StrongName Url SiteZone, 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://".

另请参阅

适用于