Assembly.LoadFile Assembly.LoadFile Assembly.LoadFile Assembly.LoadFile Method

定义

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

重载

LoadFile(String) LoadFile(String) LoadFile(String) LoadFile(String)

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

LoadFile(String, Evidence) LoadFile(String, Evidence) LoadFile(String, Evidence) LoadFile(String, Evidence)

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

LoadFile(String) LoadFile(String) LoadFile(String) 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 String String String

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

返回

加载的程序集。The loaded assembly.

异常

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

无法加载已找到的文件。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 ,并且该FileLoadException方法将引发。Starting 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.

安全性

FileIOPermission
用于从文件或目录读取的访问权限,以及用于访问路径本身中的信息的。for access to read from a file or directory, and for access to the information in the path itself. 关联的枚举ReadPathDiscoveryAssociated enumerations: Read, PathDiscovery

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

LoadFile(String, Evidence) LoadFile(String, Evidence) LoadFile(String, Evidence) 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);
[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 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);
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 String String String

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

securityEvidence
Evidence Evidence Evidence Evidence

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

返回

加载的程序集。The loaded assembly.

异常

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

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 ,并且该FileLoadException方法将引发。Starting 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.

安全性

FileIOPermission
用于从文件或目录读取的访问权限,以及用于访问路径本身中的信息的。for access to read from a file or directory, and for access to the information in the path itself. 关联的枚举ReadPathDiscoveryAssociated enumerations: Read, PathDiscovery

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

适用于