Export (0) Print
Expand All

Assembly.Load Method

Loads an assembly.

Overload List

Loads an assembly given its AssemblyName.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Load(AssemblyName) As Assembly
[C#] public static Assembly Load(AssemblyName);
[C++] public: static Assembly* Load(AssemblyName*);
[JScript] public static function Load(AssemblyName) : Assembly;

Loads the assembly with a Common Object File Format (COFF)-based image containing an emitted assembly. The assembly is loaded into the domain of the caller.

[Visual Basic] Overloads Public Shared Function Load(Byte()) As Assembly
[C#] public static Assembly Load(byte[]);
[C++] public: static Assembly* Load(unsigned char __gc[]);
[JScript] public static function Load(Byte[]) : Assembly;

Loads an assembly given the long form of its name.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Load(String) As Assembly
[C#] public static Assembly Load(string);
[C++] public: static Assembly* Load(String*);
[JScript] public static function Load(String) : Assembly;

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

[Visual Basic] Overloads Public Shared Function Load(AssemblyName, Evidence) As Assembly
[C#] public static Assembly Load(AssemblyName, Evidence);
[C++] public: static Assembly* Load(AssemblyName*, Evidence*);
[JScript] public static function Load(AssemblyName, Evidence) : Assembly;

Loads the assembly with a Common Object File Format (COFF)-based image containing an emitted assembly.

[Visual Basic] Overloads Public Shared Function Load(Byte(), Byte()) As Assembly
[C#] public static Assembly Load(byte[], byte[]);
[C++] public: static Assembly* Load(unsigned char __gc[], unsigned char __gc[]);
[JScript] public static function Load(Byte[], Byte[]) : Assembly;

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

[Visual Basic] Overloads Public Shared Function Load(String, Evidence) As Assembly
[C#] public static Assembly Load(string, Evidence);
[C++] public: static Assembly* Load(String*, Evidence*);
[JScript] public static function Load(String, Evidence) : Assembly;

Loads the assembly with a Common Object File Format (COFF)-based image containing an emitted assembly.

[Visual Basic] Overloads Public Shared Function Load(Byte(), Byte(), Evidence) As Assembly
[C#] public static Assembly Load(byte[], byte[], Evidence);
[C++] public: static Assembly* Load(unsigned char __gc[], unsigned char __gc[], Evidence*);
[JScript] public static function Load(Byte[], Byte[], Evidence) : Assembly;

Example

[Visual Basic, C#, C++] 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.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Load. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
Imports System.Reflection

Class Class1
    Public Shared Sub Main()
        Dim SampleAssembly As [Assembly]
        ' You must supply a valid fully qualified assembly name here.            
        SampleAssembly = [Assembly].Load("Assembly text name, Version, Culture, PublicKeyToken")
        Dim Types As Type() = SampleAssembly.GetTypes()
        Dim oType As Type
        ' Display all the types contained in the specified assembly.
        For Each oType In Types
            Console.WriteLine(oType.Name.ToString())
        Next oType
    End Sub 'LoadSample
End Class 'Class1

[C#] 
using System;
using System.Reflection;

class Class1
{
    public static void Main()
    {
        Assembly SampleAssembly;
        // You must supply a valid fully qualified assembly name here.            
        SampleAssembly = Assembly.Load("Assembly text name, Version, Culture, PublicKeyToken");
        Type[] Types = SampleAssembly.GetTypes();
        // Display all the types contained in the specified assembly.
        foreach (Type oType in Types)
        {
            Console.WriteLine(oType.Name.ToString());
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Reflection;

int main() 
{
   Assembly* SampleAssembly;
   // You must supply a valid fully qualified assembly name here.            
   SampleAssembly = Assembly::Load(S"Assembly text name, Version, Culture, PublicKeyToken");
   Type* Types[] = SampleAssembly->GetTypes();
   // Display all the types contained in the specified assembly.
   IEnumerator* myEnum = Types->GetEnumerator();
   while (myEnum->MoveNext())
   {
      Type* oType = __try_cast<Type*>(myEnum->Current);
      Console::WriteLine(oType->Name);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Assembly Class | Assembly Members | System.Reflection Namespace

Show:
© 2014 Microsoft