Assembly.Load Assembly.Load Assembly.Load Assembly.Load Method

Definition

Loads an assembly.

Overloads

Load(AssemblyName) Load(AssemblyName) Load(AssemblyName) Load(AssemblyName)

Loads an assembly given its AssemblyName.

Load(Byte[], Byte[], SecurityContextSource) Load(Byte[], Byte[], SecurityContextSource) Load(Byte[], Byte[], SecurityContextSource)

Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly, optionally including symbols and specifying the source for the security context. The assembly is loaded into the application domain of the caller.

Load(Byte[], Byte[], Evidence) Load(Byte[], Byte[], Evidence) Load(Byte[], Byte[], Evidence) Load(Byte[], Byte[], Evidence)

Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly, optionally including symbols and evidence for the assembly. The assembly is loaded into the application domain of the caller.

Load(String, Evidence) Load(String, Evidence) Load(String, Evidence) Load(String, Evidence)

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

Load(Byte[]) Load(Byte[]) Load(Byte[]) Load(Byte[])

Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly. The assembly is loaded into the application domain of the caller.

Load(Byte[], Byte[]) Load(Byte[], Byte[]) Load(Byte[], Byte[]) Load(Byte[], Byte[])

Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly, optionally including symbols for the assembly. The assembly is loaded into the application domain of the caller.

Load(String) Load(String) Load(String) Load(String)

Loads an assembly given the long form of its name.

Load(AssemblyName, Evidence) Load(AssemblyName, Evidence) Load(AssemblyName, Evidence) Load(AssemblyName, Evidence)

Loads an assembly given its AssemblyName. The assembly is loaded into the domain of the caller using the supplied evidence.

Load(AssemblyName) Load(AssemblyName) Load(AssemblyName) Load(AssemblyName)

Loads an assembly given its AssemblyName.

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

assemblyRef
AssemblyName AssemblyName AssemblyName AssemblyName

The object that describes the assembly to be loaded.

Returns

The loaded assembly.

Exceptions

In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, IOException, instead.

A file that was found could not be loaded.

-or-

assemblyRef specifies a remote assembly, but the ability to execute code in remote assemblies is disabled. See <loadFromRemoteSources>.

assemblyRef is not a valid assembly. -or-

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

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)
      Next
   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

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. Starting with .NET Framework 4, because execution of code in remote assemblies is disabled by default, a FileLoadException is also thrown if assemblyRef specifies a remote assembly. To enable execution of code loaded from remote locations, you can use the <loadFromRemoteSources> configuration element.

Note

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. This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    Note

    In the .NET Framework version 1.0 and in version 1.1 without SP1, when you use a Load method overload with a Byte[] parameter to load a COFF image, evidence is combined. Zone, Url and Site are inherited from the calling assembly, and Hash and StrongName are taken from the COFF 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.

Reflecting on C++ executable files might throw a BadImageFormatException. This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

Note

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.

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

WebPermission
for reading a URI that does not begin with "file://".

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

See Also

Load(Byte[], Byte[], SecurityContextSource) Load(Byte[], Byte[], SecurityContextSource) Load(Byte[], Byte[], SecurityContextSource)

Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly, optionally including symbols and specifying the source for the security context. The assembly is loaded into the application domain of the caller.

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

Parameters

rawAssembly
Byte[]

A byte array that is a COFF-based image containing an emitted assembly.

rawSymbolStore
Byte[]

A byte array that contains the raw bytes representing the symbols for the assembly.

securityContextSource
SecurityContextSource SecurityContextSource SecurityContextSource SecurityContextSource

The source of the security context.

Returns

The loaded assembly.

Exceptions

rawAssembly is not a valid assembly.

-or-

rawAssembly was compiled with a later version of the common language runtime than the version that is currently loaded.

The value of securityContextSource is not one of the enumeration values.

Remarks

The assembly is loaded into the application domain of the caller using the specified source for the security context. If rawSymbolStore was specified, the raw bytes that represent the symbols for the assembly are also loaded.

Load(Byte[], Byte[], Evidence) Load(Byte[], Byte[], Evidence) Load(Byte[], Byte[], Evidence) Load(Byte[], Byte[], Evidence)

Warning

This API is now obsolete.

Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly, optionally including symbols and evidence for the assembly. The assembly is loaded into the application domain of the caller.

public:
 static System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly, cli::array <System::Byte> ^ rawSymbolStore, 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 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
Public Shared Function Load (rawAssembly As Byte(), rawSymbolStore As Byte(), securityEvidence As Evidence) As Assembly

Parameters

rawAssembly
Byte[]

A byte array that is a COFF-based image containing an emitted assembly.

rawSymbolStore
Byte[]

A byte array that contains the raw bytes representing the symbols for the assembly.

securityEvidence
Evidence Evidence Evidence Evidence

Evidence for loading the assembly.

Returns

The loaded assembly.

Exceptions

rawAssembly is not a valid assembly.

-or-

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

An assembly or module was loaded twice with two different evidences.

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

The assembly is loaded into the domain of the caller 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. This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    Note

    In the .NET Framework version 1.0 and in version 1.1 without SP1, when you use a Load method overload with a Byte[] parameter to load a COFF image, evidence is combined. Zone, Url and Site are inherited from the calling assembly, and Hash and StrongName are taken from the COFF 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.

Reflecting on C++ executable files might throw a BadImageFormatException. This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

If you call the [], Byte<xref:System.Reflection.Assembly.Load%2A> 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.

Note that this method overload always creates a new Assembly object with its own mapping.

Security

SecurityPermission
for the ability to supply evidence. Associated enumeration: ControlEvidence. Security action: Demand.

Load(String, Evidence) Load(String, Evidence) Load(String, Evidence) Load(String, Evidence)

Warning

This API is now obsolete.

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

public:
 static System::Reflection::Assembly ^ Load(System::String ^ assemblyString, System::Security::Policy::Evidence ^ assemblySecurity);
[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 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
Public Shared Function Load (assemblyString As String, assemblySecurity As Evidence) As Assembly

Parameters

assemblyString
String String String String

The display name of the assembly.

assemblySecurity
Evidence Evidence Evidence Evidence

Evidence for loading the assembly.

Returns

The loaded assembly.

Exceptions

assemblyString is not a valid assembly.

-or-

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

A file that was found could not be loaded.

-or-

An assembly or module was loaded twice with two different evidences.

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. This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    Note

    In the .NET Framework version 1.0 and in version 1.1 without SP1, when you use a Load method overload with a Byte[] parameter to load a COFF image, evidence is combined. Zone, Url and Site are inherited from the calling assembly, and Hash and StrongName are taken from the COFF 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.

Reflecting on C++ executable files might throw a BadImageFormatException. This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

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.

Security

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

See Also

Load(Byte[]) Load(Byte[]) Load(Byte[]) Load(Byte[])

Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly. The assembly is loaded into the application domain of the caller.

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

rawAssembly
Byte[]

A byte array that is a COFF-based image containing an emitted assembly.

Returns

The loaded assembly.

Exceptions

rawAssembly is not a valid assembly.

-or-

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

Remarks

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.

Reflecting on C++ executable files might throw a BadImageFormatException. This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

Note that this method overload always creates a new Assembly object with its own mapping.

Load(Byte[], Byte[]) Load(Byte[], Byte[]) Load(Byte[], Byte[]) Load(Byte[], Byte[])

Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly, optionally including symbols for the assembly. The assembly is loaded into the application domain of the caller.

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);
static member Load : byte[] * byte[] -> System.Reflection.Assembly
Public Shared Function Load (rawAssembly As Byte(), rawSymbolStore As Byte()) As Assembly

Parameters

rawAssembly
Byte[]

A byte array that is a COFF-based image containing an emitted assembly.

rawSymbolStore
Byte[]

A byte array that contains the raw bytes representing the symbols for the assembly.

Returns

The loaded assembly.

Exceptions

rawAssembly is not a valid assembly.

-or-

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

Remarks

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.

Reflecting on C++ executable files might throw a BadImageFormatException. This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

Note that this method overload always creates a new Assembly object with its own mapping.

Load(String) Load(String) Load(String) Load(String)

Loads an assembly given the long form of its name.

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

assemblyString
String String String String

The long form of the assembly name.

Returns

The loaded assembly.

Exceptions

A file that was found could not be loaded.

assemblyString is not a valid assembly.

-or-

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

Examples

The following example loads an assembly given its fully qualified name, and lists all the types contained in the specified assembly. For this code example to run, you must provide the fully qualified assembly name. 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
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 'Class1

Remarks

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...");
      else
         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...")
      Else
         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.

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. This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    Note

    In the .NET Framework version 1.0 and in version 1.1 without SP1, when you use a Load method overload with a Byte[] parameter to load a COFF image, evidence is combined. Zone, Url and Site are inherited from the calling assembly, and Hash and StrongName are taken from the COFF 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.

Reflecting on C++ executable files might throw a BadImageFormatException. This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

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.

Security

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

See Also

Load(AssemblyName, Evidence) Load(AssemblyName, Evidence) Load(AssemblyName, Evidence) Load(AssemblyName, Evidence)

Warning

This API is now obsolete.

Loads an assembly given its AssemblyName. The assembly is loaded into the domain of the caller using the supplied evidence.

public:
 static System::Reflection::Assembly ^ Load(System::Reflection::AssemblyName ^ assemblyRef, System::Security::Policy::Evidence ^ assemblySecurity);
[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 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
Public Shared Function Load (assemblyRef As AssemblyName, assemblySecurity As Evidence) As Assembly

Parameters

assemblyRef
AssemblyName AssemblyName AssemblyName AssemblyName

The object that describes the assembly to be loaded.

assemblySecurity
Evidence Evidence Evidence Evidence

Evidence for loading the assembly.

Returns

The loaded assembly.

Exceptions

assemblyRef is not a valid assembly.

-or-

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

An assembly or module was loaded twice with two different evidences.

-or-

assemblyRef specifies a remote assembly, but the ability to execute code in remote assemblies is disabled. See <loadFromRemoteSources>.

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. Starting with .NET Framework 4, because execution of code in remote assemblies is disabled by default, a FileLoadException is also thrown if assemblyRef specifies a remote assembly. To enable execution of code loaded from remote locations, you can use the <loadFromRemoteSources> configuration element.

Note

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. This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    Note

    In the .NET Framework version 1.0 and in version 1.1 without SP1, when you use a Load method overload with a Byte[] parameter to load a COFF image, evidence is combined. Zone, Url and Site are inherited from the calling assembly, and Hash and StrongName are taken from the COFF 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.

Reflecting on C++ executable files might throw a BadImageFormatException. This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

Note

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.

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

WebPermission
for reading a URI that does not begin with "file://".

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

See Also

Applies to