Assembly.LoadFile Method (String, Evidence)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

obsoleteCodeEntityM:System.Reflection.Assembly.LoadFile(System.String) Note: This API is now obsolete.

Loads an assembly given its path, loading the assembly into the domain of the caller using the supplied evidence.

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

[<ObsoleteAttribute("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 for more information.")>]
[<SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlEvidence)>]
static member LoadFile : 
        path:string *
        securityEvidence:Evidence -> Assembly


Type: System.String

The fully qualified path of the assembly file.

Type: System.Security.Policy.Evidence

Evidence for loading the assembly.

Return Value

Type: System.Reflection.Assembly

The loaded assembly.

Exception Condition

The path argument is not an absolute path.


The path parameter is null.


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


A file that was found could not be loaded.


path is not a valid assembly.


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.

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.


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


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

.NET Framework
Available since 1.1
Return to top