Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Assembly.Load Method (String)

Loads an assembly given the long form of its name.

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

public static Assembly Load (
	string assemblyString
)
public static Assembly Load (
	String assemblyString
)
public static function Load (
	assemblyString : String
) : Assembly

Parameters

assemblyString

The long form of the assembly name.

Return Value

The loaded assembly.

Exception typeCondition

ArgumentNullException

assemblyString is a null reference (Nothing in Visual Basic).

ArgumentException

assemblyString is a zero-length string.

FileNotFoundException

assemblyString is not found.

FileLoadException

A file that was found could not be loaded.

BadImageFormatException

assemblyString is not a valid assembly.

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 with a Byte[] parameter to load a common object file format (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 common object file format (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 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.

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 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);
        }
    }
}

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

Show:
© 2016 Microsoft