Assembly.UnsafeLoadFrom(String) Assembly.UnsafeLoadFrom(String) Assembly.UnsafeLoadFrom(String) Assembly.UnsafeLoadFrom(String) Method

定义

绕过某些安全检查,将程序集加载到加载源上下文中。Loads an assembly into the load-from context, bypassing some security checks.

public:
 static System::Reflection::Assembly ^ UnsafeLoadFrom(System::String ^ assemblyFile);
[System.Security.SecurityCritical]
public static System.Reflection.Assembly UnsafeLoadFrom (string assemblyFile);
static member UnsafeLoadFrom : string -> System.Reflection.Assembly
Public Shared Function UnsafeLoadFrom (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.

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

-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.

注解

使用此方法加载操作系统已标记为已从 Web 加载的本地程序集 (例如, 从 Internet 或 intranet 下载的临时文件)。Use this method to load a local assembly that the operating system has flagged as having been loaded from the Web (for example, a temporary file that was downloaded from the Internet or intranet). .NET Framework 4.NET Framework 4之前, 此类程序集会自动加载到沙盒应用程序域中。Before the .NET Framework 4.NET Framework 4, such assemblies were automatically loaded into a sandboxed application domain. 从开始, 以完全信任方式加载它们。 .NET Framework 4.NET Framework 4Starting with the .NET Framework 4.NET Framework 4, they are loaded with full trust.

作为使用此方法的替代方法, 可以在应用程序配置文件中应用 <y>元素As an alternative to using this method, you can apply the <NetFx40_LegacySecurityPolicy> Element in your application configuration file. 这会导致公共语言运行时恢复到的 .NET Framework 3.5.NET Framework 3.5安全策略。This causes the common language runtime to revert to the security policy of the .NET Framework 3.5.NET Framework 3.5.

注意

如果使用上述任一解决方案, 则必须确保以完全信任方式加载assemblyFile是安全的。If you use either of these solutions, you must be certain that it is safe to load assemblyFile with full trust.

有关加载上下文的讨论, 包括加载源上下文, 请参阅LoadFrom(String)方法重载。For a discussion of load contexts, including the load-from context, see the LoadFrom(String) method overload.

安全性

SecurityCriticalAttribute
需要对直接调用方的完全信任。requires full trust for the immediate caller. 部分受信任的或透明的代码不能使用此成员。This member cannot be used by partially trusted or transparent code.

适用于