Access to this page requires authorization. You can try
signing in
or
changing directories
.
Access to this page requires authorization. You can try
changing directories
.
public:
static System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly, cli::array <System::Byte> ^ rawSymbolStore, System::Security::SecurityContextSource securityContextSource);
public static System.Reflection.Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore, System.Security.SecurityContextSource securityContextSource);
static member Load : byte[] * byte[] * System.Security.SecurityContextSource -> System.Reflection.Assembly
Public Shared Function Load (rawAssembly As Byte(), rawSymbolStore As Byte(), securityContextSource As SecurityContextSource) As Assembly
Parameters
public:
static System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly, cli::array <System::Byte> ^ rawSymbolStore, System::Security::Policy::Evidence ^ securityEvidence);
public static System.Reflection.Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore, 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 Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public static System.Reflection.Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore, System.Security.Policy.Evidence securityEvidence);
static member Load : byte[] * byte[] * 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 Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>]
static member Load : byte[] * byte[] * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Shared Function Load (rawAssembly As Byte(), rawSymbolStore As Byte(), securityEvidence As Evidence) As Assembly
Parameters
Remarks
This method overload always creates a new
Assembly
object in its own isolated load context.
The assembly is loaded using the supplied evidence. The raw bytes representing the symbols for the assembly are also loaded.
Whether certain permissions are granted or not granted to an assembly is based on evidence. The rules for assembly and security evidence merging are as follows:
When you use a
Load
method with no
Evidence
parameter, the assembly is loaded with the evidence that the loader supplies.
When you use a
Load
method with an
Evidence
parameter, pieces of evidence are merged. Pieces of evidence supplied as an argument to the
Load
method supersede pieces of evidence supplied by the loader.
When you use a
Load
method overload with a
Byte[]
parameter to load a COFF image, evidence is inherited from the calling assembly.
When you use a
Load
method with a
Byte[]
parameter and
Evidence
to load a COFF image, only the supplied evidence is used. Evidence of the calling assembly and evidence of the COFF image are ignored.
If you call the
Load
method more than once on the same assembly but with a different evidence specified, the common language runtime does not throw a
FileLoadException
because the equality and integrity of the different evidence specifications cannot be determined. The evidence that first succeeds is the evidence that is used.
public:
static System::Reflection::Assembly ^ Load(System::String ^ assemblyString, System::Security::Policy::Evidence ^ assemblySecurity);
public static System.Reflection.Assembly Load(string assemblyString, System.Security.Policy.Evidence assemblySecurity);
[System.Obsolete("This method is obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public static System.Reflection.Assembly Load(string assemblyString, System.Security.Policy.Evidence assemblySecurity);
static member Load : 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 Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>]
static member Load : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Shared Function Load (assemblyString As String, assemblySecurity As Evidence) As Assembly
Parameters
Remarks
FileLoadException
is thrown if
assemblyString
specifies the full assembly name, and the first assembly that matches the simple name has a different version, culture, or public key token. The loader does not continue probing for other assemblies that match the simple name.
Whether certain permissions are granted or not granted to an assembly is based on evidence. The rules for assembly and security evidence merging are as follows:
When you use a
Load
method with no
Evidence
parameter, the assembly is loaded with the evidence that the loader supplies.
When you use a
Load
method with an
Evidence
parameter, pieces of evidence are merged. Pieces of evidence supplied as an argument to the
Load
method supersede pieces of evidence supplied by the loader.
When you use a
Load
method overload with a
Byte[]
parameter to load a common object file format (COFF) image, evidence is inherited from the calling assembly.
When you use a
Load
method with a
Byte[]
parameter and
Evidence
to load a COFF image, only the supplied evidence is used. Evidence of the calling assembly and evidence of the COFF image is ignored.
If you call this method more than once on the same assembly but with a different evidence specified, the common language runtime does not throw a
FileLoadException
because the equality and integrity of the different evidence specifications cannot be determined. The evidence that first succeeds is the evidence that is used.
In the .NET Framework version 2.0, processor architecture is added to assembly identity, and can be specified as part of assembly name strings. For example, "ProcessorArchitecture=msil". However, the recommended way to specify an assembly name is to create an
AssemblyName
object and pass it to an appropriate overload of the
Load
method. See
AssemblyName.ProcessorArchitecture
.
public:
static System::Reflection::Assembly ^ Load(System::Reflection::AssemblyName ^ assemblyRef, System::Security::Policy::Evidence ^ assemblySecurity);
public static System.Reflection.Assembly Load(System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity);
[System.Obsolete("This method is obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public static System.Reflection.Assembly Load(System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity);
static member Load : System.Reflection.AssemblyName * 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 Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>]
static member Load : System.Reflection.AssemblyName * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Shared Function Load (assemblyRef As AssemblyName, assemblySecurity As Evidence) As Assembly
Parameters
Remarks
FileLoadException
is thrown if
assemblyRef
specifies the full assembly name, and the first assembly that matches the simple name has a different version, culture, or public key token. The loader does not continue probing for other assemblies that match the simple name.
See
<loadFromRemoteSources>
for loading assemblies from remote locations.
Do not use an
AssemblyName
with only the
CodeBase
property set. The
CodeBase
property does not supply any elements of the assembly identity (such as name or version), so loading does not occur according to load-by-identity rules, as you would expect from the
Load
method. Instead, the assembly is loaded using load-from rules. For information about the disadvantages of using the load-from context, see the
Assembly.LoadFrom
method overload or
Best Practices for Assembly Loading
.
Whether certain permissions are granted or not granted to an assembly is based on evidence. The rules for assembly and security evidence merging are as follows:
When you use a
Load
method with no
Evidence
parameter, the assembly is loaded with the evidence that the loader supplies.
When you use a
Load
method with an
Evidence
parameter, pieces of evidence are merged. Pieces of evidence supplied as an argument to the
Load
method supersede pieces of evidence supplied by the loader.
When you use a
Load
method overload with a
Byte[]
parameter to load a common object file format (COFF) image, evidence is inherited from the calling assembly.
When you use a
Load
method with a
Byte[]
parameter and
Evidence
to load a COFF image, only the supplied evidence is used. Evidence of the calling assembly and evidence of the COFF image is ignored.
If both the
AssemblyName.Name
property and the
AssemblyName.CodeBase
property are set, the first attempt to load the assembly uses the display name (including version, culture, and so on, as returned by the
Assembly.FullName
property). If the file is not found,
CodeBase
is used to search for the assembly. If the assembly is found using
CodeBase
, the display name is matched against the assembly. If the match fails, a
FileLoadException
is thrown.
If you call the
Load
method more than once on the same assembly but with a different evidence specified, the common language runtime does not throw a
FileLoadException
because the equality and integrity of the different evidence specifications cannot be determined. The evidence that first succeeds is the evidence that is used.
public:
static System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly);
public static System.Reflection.Assembly Load(byte[] rawAssembly);
static member Load : byte[] -> System.Reflection.Assembly
Public Shared Function Load (rawAssembly As Byte()) As Assembly
Parameters
Remarks
This method overload always creates a new
Assembly
object in its own isolated load context.
.NET Framework only:
The trust level of an assembly that is loaded by using this method is the same as the trust level of the calling assembly. To load an assembly from a byte array with the trust level of the application domain, use the
Load(Byte[], Byte[], SecurityContextSource)
method overload. For more information about the use of evidence with overloads of the
Load
method that take byte arrays, see the
Load(Byte[], Byte[], Evidence)
method overload.
public:
static System::Reflection::Assembly ^ Load(System::String ^ assemblyString);
public static System.Reflection.Assembly Load(string assemblyString);
static member Load : string -> System.Reflection.Assembly
Public Shared Function Load (assemblyString As String) As Assembly
Parameters
Examples
The following example loads an assembly given its fully qualified name, and lists all the types contained in the specified assembly. For information about how to obtain the fully qualified assembly name, see
Assembly Names
.
using namespace System;
using namespace System::Collections;
using namespace System::Reflection;
int main()
// You must supply a valid fully qualified assembly name.
Assembly^ SampleAssembly = Assembly::Load
( "SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3" );
array<Type^>^ Types = SampleAssembly->GetTypes();
// Display all the types contained in the specified assembly.
IEnumerator^ myEnum = Types->GetEnumerator();
Type^ oType;
while ( myEnum->MoveNext() )
oType = safe_cast<Type^>(myEnum->Current);
Console::WriteLine( oType->Name );
using System;
using System.Reflection;
class Class1
public static void Main()
// You must supply a valid fully qualified assembly name.
Assembly SampleAssembly = Assembly.Load
("SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3");
// Display all the types contained in the specified assembly.
foreach (Type oType in SampleAssembly.GetTypes()) {
Console.WriteLine(oType.Name);
Imports System.Reflection
Class Class1
Public Shared Sub Main()
' You must supply a valid fully qualified assembly name.
Dim SampleAssembly As [Assembly] = _
[Assembly].Load("SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3")
Dim oType As Type
' Display all the types contained in the specified assembly.
For Each oType In SampleAssembly.GetTypes()
Console.WriteLine(oType.Name)
Next oType
End Sub 'LoadSample
End Class
Remarks
In .NET Core/5+, the target assembly is loaded into the current AssemblyLoadContext. For more information on assembly loading, see Managed assembly loading algorithm.
To load the correct assembly, it's recommended to call the Load
method by passing the long form of the assembly name. The long form of an assembly name consists of its simple name (such as "System" for the System.dll assembly) along with its version, culture, public key token, and optionally its processor architecture. It corresponds to the assembly's FullName property. The following example illustrates the use of a long name to load the System.dll assembly for the .NET Framework 4:
using System;
using System.Reflection;
public class Example
public static void Main()
string longName = "system, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
Assembly assem = Assembly.Load(longName);
if (assem == null)
Console.WriteLine("Unable to load assembly...");
Console.WriteLine(assem.FullName);
// The example displays the following output:
// system, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Imports System.Reflection
Module Example
Public Sub Main()
Dim longName As String = "system, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
Dim assem As Assembly = Assembly.Load(longName)
If assem Is Nothing Then
Console.WriteLine("Unable to load assembly...")
Console.WriteLine(assem.FullName)
End If
End Sub
End Module
' The example displays the following output:
' system, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
FileLoadException is thrown if assemblyString
specifies the full assembly name, and the first assembly that matches the simple name has a different version, culture, or public key token. The loader does not continue probing for other assemblies that match the simple name.
In the .NET Framework version 2.0, processor architecture is added to assembly identity, and can be specified as part of assembly name strings. For example, "ProcessorArchitecture=msil". However, the recommended way to specify an assembly name is to create an AssemblyName object and pass it to an appropriate overload of the Load method. See AssemblyName.ProcessorArchitecture.
public:
static System::Reflection::Assembly ^ Load(System::Reflection::AssemblyName ^ assemblyRef);
public static System.Reflection.Assembly Load(System.Reflection.AssemblyName assemblyRef);
static member Load : System.Reflection.AssemblyName -> System.Reflection.Assembly
Public Shared Function Load (assemblyRef As AssemblyName) As Assembly
Parameters
A file that was found could not be loaded.
.NET Framework only: assemblyRef
specifies a location that is disabled based on <loadFromRemoteSources>.
Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, IOException, instead.
Examples
The following example instantiates an AssemblyName object and uses it to load the sysglobal.dll
assembly. The example then displays the full name of the assembly's public types.
using System;
using System.Reflection;
public class Example
public static void Main()
String fullName = "sysglobl, Version=4.0.0.0, Culture=neutral, " +
"PublicKeyToken=b03f5f7f11d50a3a, processor architecture=MSIL";
var an = new AssemblyName(fullName);
var assem = Assembly.Load(an);
Console.WriteLine("Public types in assembly {0}:", assem.FullName);
foreach (var t in assem.GetTypes())
if (t.IsPublic)
Console.WriteLine(" {0}", t.FullName);
// The example displays the following output:
// Public types in assembly sysglobl, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a:
// System.Globalization.CultureAndRegionInfoBuilder
// System.Globalization.CultureAndRegionModifiers
Imports System.Reflection
Module Example
Public Sub Main()
Dim fullName As String = "sysglobl, Version=4.0.0.0, Culture=neutral, " +
"PublicKeyToken=b03f5f7f11d50a3a, processor architecture=MSIL"
Dim an As New AssemblyName(fullName)
Dim assem As Assembly = Assembly.Load(an)
Console.WriteLine("Public types in assembly {0}:", assem.FullName)
For Each t As Type in assem.GetTypes()
If t.IsPublic Then Console.WriteLine(" {0}", t.FullName)
End Sub
End Module
' The example displays the following output:
' Public types in assembly sysglobl, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a:
' System.Globalization.CultureAndRegionInfoBuilder
' System.Globalization.CultureAndRegionModifiers
Remarks
In .NET Core/.NET 5+, the target assembly will be loaded into the current AssemblyLoadContext. For more information on assembly loading, see Managed assembly loading algorithm.
.NET Framework only: For information about loading assemblies from remote locations, see <loadFromRemoteSources>
.
.NET Framework only: Do not use an AssemblyName with only the CodeBase property set. The CodeBase property does not supply any elements of the assembly identity (such as name or version), so loading does not occur according to load-by-identity rules, as you would expect from the Load method. Instead, the assembly is loaded using load-from rules. For information about the disadvantages of using the load-from context, see the Assembly.LoadFrom method overload or Best Practices for Assembly Loading.
.NET Framework only: If both the AssemblyName.Name property and the AssemblyName.CodeBase property are set, the first attempt to load the assembly uses the display name (including version, culture, and so on, as returned by the Assembly.FullName property). If the file is not found, CodeBase is used to search for the assembly. If the assembly is found using CodeBase, the display name is matched against the assembly. If the match fails, a FileLoadException is thrown.
public:
static System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly, cli::array <System::Byte> ^ rawSymbolStore);
public static System.Reflection.Assembly Load(byte[] rawAssembly, byte[]? rawSymbolStore);
public static System.Reflection.Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore);
static member Load : byte[] * byte[] -> System.Reflection.Assembly
Public Shared Function Load (rawAssembly As Byte(), rawSymbolStore As Byte()) As Assembly
Parameters
Remarks
In .NET Core/5+, the target assembly is loaded into the current AssemblyLoadContext. For more information on assembly loading, see Managed assembly loading algorithm.
This method overload always creates a new Assembly object in its own isolated load context.
.NET Framework only: The trust level of an assembly that is loaded by using this method is the same as the trust level of the calling assembly. To load an assembly from a byte array with the trust level of the application domain, use the Load(Byte[], Byte[], SecurityContextSource) method overload. For more information about the use of evidence with overloads of the Load method that take byte arrays, see the Load(Byte[], Byte[], Evidence) method overload.