Assembly.LoadFile 方法

定义

加载程序集文件的内容。Loads the contents of an assembly file.

重载

LoadFile(String)

加载指定路径中程序集文件的内容。Loads the contents of an assembly file on the specified path.

LoadFile(String, Evidence)

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

LoadFile(String)

加载指定路径中程序集文件的内容。Loads the contents of an assembly file on the specified path.

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

参数

path
String

要加载的文件的完全限定路径。The fully qualified path of the file to load.

返回

加载的程序集。The loaded assembly.

异常

path 参数不是绝对路径。The path argument is not an absolute path.

path 参数为 nullThe path parameter is null.

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

-或--or-

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

path 参数为空字符串 ("") 或不存在。The path parameter is an empty string ("") or does not exist.

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

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

注解

使用 LoadFile 方法加载和检查具有相同标识但位于不同路径中的程序集。Use the LoadFile method to load and examine assemblies that have the same identity, but are located in different paths. LoadFile 不会将文件加载到加载源上下文中,也不会使用加载路径解析依赖项,因为 LoadFrom 方法这样做。LoadFile does not load files into the load-from context, and does not resolve dependencies using the load path, as the LoadFrom method does. LoadFile 在这种受限情况下非常有用,因为 LoadFrom 不能用于加载具有相同标识但路径不同的程序集;它将只加载第一个此类程序集。LoadFile is useful in this limited scenario because LoadFrom cannot be used to load assemblies that have the same identities but different paths; it will load only the first such assembly.

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

LoadFile(String, Evidence)

警告

此 API 现已过时。

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

public:
 static System::Reflection::Assembly ^ LoadFile(System::String ^ path, System::Security::Policy::Evidence ^ securityEvidence);
public static System.Reflection.Assembly LoadFile (string path, System.Security.Policy.Evidence securityEvidence);
[System.Obsolete("This method is obsolete and will be removed in a future release of the .NET Framework. Please use an overload of LoadFile which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public static System.Reflection.Assembly LoadFile (string path, System.Security.Policy.Evidence securityEvidence);
[System.Obsolete]
public static System.Reflection.Assembly LoadFile (string path, System.Security.Policy.Evidence securityEvidence);
static member LoadFile : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Shared Function LoadFile (path As String, securityEvidence As Evidence) As Assembly

参数

path
String

程序集文件的完全限定路径。The fully qualified path of the assembly file.

securityEvidence
Evidence

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

返回

加载的程序集。The loaded assembly.

属性

异常

path 参数不是绝对路径。The path argument is not an absolute path.

path 参数为 nullThe path parameter is null.

path 参数为空字符串 ("") 或不存在。The path parameter is an empty string ("") or does not exist.

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

-或--or-

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

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

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

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.

注解

使用 LoadFile 方法加载和检查具有相同标识但位于不同路径中的程序集。Use the LoadFile method to load and examine assemblies that have the same identity, but are located in different paths. LoadFile 不会将文件加载到 LoadFrom 上下文中,并且不会使用加载路径解析依赖项,因为 LoadFrom 方法。LoadFile does not load files into the LoadFrom context, and does not resolve dependencies using the load path, as the LoadFrom method does. LoadFile 在这种受限情况下非常有用,因为 LoadFrom 不能用于加载具有相同标识但路径不同的程序集;它将只加载第一个此类程序集。LoadFile is useful in this limited scenario because LoadFrom cannot be used to load assemblies that have the same identities but different paths; it will load only the first such assembly.

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

适用于