Assembly.LoadFile Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Loads the contents of an assembly file.
LoadFile(String, Evidence) |
Obsolete.
Loads an assembly given its path, loading the assembly using the supplied evidence. |
LoadFile(String) |
Loads the contents of an assembly file on the specified path. |
Caution
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.
Loads an assembly given its path, loading the assembly using the supplied evidence.
public:
static System::Reflection::Assembly ^ LoadFile(System::String ^ path, System::Security::Policy::Evidence ^ securityEvidence);
public static System.Reflection.Assembly LoadFile (string path, System.Security.Policy.Evidence securityEvidence);
[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
[<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.")>]
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
The fully qualified path of the assembly file.
- securityEvidence
- Evidence
Evidence for loading the assembly.
Returns
The loaded assembly.
- Attributes
Exceptions
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.
-or-
path
specifies a location that is disabled based on <loadFromRemoteSources>.
path
is not a valid assembly for the currently loaded runtime.
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.
See <loadFromRemoteSources>
for loading assemblies from remote locations.
Applies to
.NET Framework 4.8.1 and other versions
Product | Versions (Obsolete) |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5 (4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1) |
- Source:
- Assembly.cs
- Source:
- Assembly.cs
- Source:
- Assembly.cs
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
The fully qualified path of the file to load.
Returns
The loaded assembly.
Exceptions
The path
argument is not an absolute path.
The path
parameter is null
.
A file that was found could not be loaded.
-or-
.NET Framework only: path
specifies a location that is disabled based on <loadFromRemoteSources>.
The path
parameter is an empty string ("") or does not exist.
path
is not a valid assembly for the currently loaded runtime.
Remarks
This API is present in .NET Core for compatibility, but it is recommended to use AssemblyLoadContext overloads in .NET Core 2.0 and later.
The assembly is loaded into a new AssemblyLoadContext created for this purpose. For more information on assembly loading, see Managed assembly loading algorithm.
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.
.NET Framework only: See <loadFromRemoteSources>
for loading assemblies from remote locations.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: