Assembly.LoadFile Method (String) (System.Reflection)

Switch View :
ScriptFree
.NET Framework Class Library
Assembly.LoadFile Method (String)

Loads the contents of an assembly file on the specified path.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)
Syntax

Visual Basic
Public Shared Function LoadFile ( _
	path As String _
) As Assembly
C#
public static Assembly LoadFile(
	string path
)
Visual C++
public:
static Assembly^ LoadFile(
	String^ path
)
F#
static member LoadFile : 
        path:string -> Assembly 

Parameters

path
Type: System.String
The path of the file to load.

Return Value

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

Exception Condition
ArgumentNullException

The path parameter is null.

FileLoadException

A file that was found could not be loaded.

FileNotFoundException

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

BadImageFormatException

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

Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
.NET Framework Security

Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, 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.
See Also

Reference

Community Content

Dennis George
Assembly.LoadFrom/LoadFile/Load(byte[]) prefers GAC
According to: http://blogs.msdn.com/b/junfeng/archive/2004/11/03/252033.aspx

Starting in Whidbey beta2, for Assembly.LoadFrom/LoadFile/Load(byte[]), if there is an assembly in GAC with exactly the same assembly identity, we will return the one in GAC.

ReflectionOnlyLoad and ReflectionOnlyLoadFrom APIs are not affected.