Skip to main content
.NET Framework Class Library
Assembly..::.UnsafeLoadFrom Method

Loads an assembly into the load-from context, bypassing some security checks.

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Syntax
Public Shared Function UnsafeLoadFrom ( _
	assemblyFile As String _
) As Assembly
public static Assembly UnsafeLoadFrom(
	string assemblyFile
)
public:
static Assembly^ UnsafeLoadFrom(
	String^ assemblyFile
)
static member UnsafeLoadFrom : 
        assemblyFile:string -> Assembly 

Parameters

assemblyFile
Type: System..::.String
The name or path of the file that contains the manifest of the assembly.

Return Value

Type: System.Reflection..::.Assembly
The loaded assembly.
Exceptions
ExceptionCondition
ArgumentNullException

assemblyFile is nullNothingnullptra null reference (Nothing in Visual Basic).

FileNotFoundException

assemblyFile is not found, or the module you are trying to load does not specify a filename extension.

FileLoadException

A file that was found could not be loaded.

BadImageFormatException

assemblyFile is not a valid assembly.

-or-

assemblyFile was compiled with a later version of the common language runtime than the version that is currently loaded.

SecurityException

A codebase that does not start with "file://" was specified without the required WebPermission.

ArgumentException

The assemblyFile parameter is an empty string ("").

PathTooLongException

The assembly name is longer than MAX_PATH characters.

Remarks

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). Before the .NET Framework version 4, such assemblies were automatically loaded into a sandboxed application domain. Starting with the .NET Framework 4, they are loaded with full trust.

As an alternative to using this method, you can apply the <NetFx40_LegacySecurityPolicy> Element in your application configuration file. This causes the common language runtime to revert to the security policy of the .NET Framework version 3.5.

Caution noteCaution

If you use either of these solutions, you must be certain that it is safe to load assemblyFile with full trust.

For a discussion of load contexts, including the load-from context, see the LoadFrom(String) method overload.

Version Information

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4
.NET Framework Security
  • SecurityCriticalAttribute 

    requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Microsoft is conducting an online survey to understand your opinion of the MSDN Web site. If you choose to participate, the online survey will be presented to you when you leave the MSDN Web site.

Would you like to participate?