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

Definition

Loads the contents of an assembly file.

Overloads

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
Parameters
path
String String String String

The fully qualified path of the file to load.

Returns

The loaded assembly.

Exceptions

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

The path parameter is an empty string ("") or does not exist.

path is not a valid assembly.

-or-

Version 2.0 or later of the common language runtime is currently loaded and path was compiled with a later version.

Remarks

Use the LoadFile method to load and examine assemblies that have the same identity, but are located in different paths. 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 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.

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. To enable execution of code loaded from remote locations, you can use the <loadFromRemoteSources> configuration element.

Security

FileIOPermission
for access to read from a file or directory, and for access to the information in the path itself. Associated enumerations: Read, PathDiscovery

SecurityPermission
to load an assembly with evidence. Associated enumeration: ControlEvidence

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

Warning

This API is now obsolete.

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
Parameters
path
String String String String

The fully qualified path of the assembly file.

securityEvidence
Evidence Evidence Evidence Evidence

Evidence for loading the assembly.

Returns

The loaded assembly.

Exceptions

The path argument is not an absolute 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. See <loadFromRemoteSources>.

path is not a valid assembly.

-or-

Version 2.0 or later of the common language runtime is currently loaded and path was compiled with a later version.

securityEvidence is not null. By default, legacy CAS policy is not enabled in the .NET Framework 4; when it is not enabled, securityEvidence must be null.

Remarks

Use the LoadFile method to load and examine assemblies that have the same identity, but are located in different paths. LoadFile does not load files into the LoadFrom context, and does not resolve dependencies using the load path, as the LoadFrom method does. 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.

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. To enable execution of code loaded from remote locations, you can use the <loadFromRemoteSources> configuration element.

Security

FileIOPermission
for access to read from a file or directory, and for access to the information in the path itself. Associated enumerations: Read, PathDiscovery

SecurityPermission
to load an assembly with evidence. Associated enumeration: ControlEvidence

Applies to