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方法会抛出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.

安全性

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方法会抛出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.

安全性

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

适用于