Export (0) Print
Expand All

Assembly Class

Defines an Assembly, which is a reusable, versionable, and self-describing building block of a common language runtime application.

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

[SerializableAttribute] 
[ClassInterfaceAttribute(ClassInterfaceType.None)] 
[ComVisibleAttribute(true)] 
public class Assembly : _Assembly, IEvidenceFactory, ICustomAttributeProvider, 
	ISerializable
/** @attribute SerializableAttribute() */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.None) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class Assembly implements _Assembly, IEvidenceFactory, 
	ICustomAttributeProvider, ISerializable
SerializableAttribute 
ClassInterfaceAttribute(ClassInterfaceType.None) 
ComVisibleAttribute(true) 
public class Assembly implements _Assembly, IEvidenceFactory, 
	ICustomAttributeProvider, ISerializable

Assemblies provide the infrastructure that allows the runtime to fully understand the contents of an application and to enforce the versioning and dependency rules defined by the application. These concepts are crucial for solving the versioning problem and for simplifying the deployment of runtime applications.

The following code example lists the method signatures for each method in an assembly.

// LoadInvoke loads MyAssembly.dll and lists the method
// information for each method. After compiling this class,
// run LoadInvoke.exe with the DisplayName for the assembly,
// as shown here:
// LoadInvoke MyAssembly

using System;
using System.Reflection;
using System.Security.Permissions;

public class LoadInvoke
{
    [PermissionSetAttribute(SecurityAction.Demand, Name="FullTrust")]
    public static void Main(string[] args)
    {
        Assembly a = Assembly.Load(args[0]);
        Type[] mytypes = a.GetTypes();
        BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
            BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);

        foreach(Type t in mytypes)
        {
            MethodInfo[] mi = t.GetMethods(flags);
            Object obj = Activator.CreateInstance(t);

            foreach(MethodInfo m in mi)
            {
                // Instead of invoking the methods,
                // it's safer to initially just list them.
                Console.WriteLine(m);
            }
        }
    }
}

// Use this class with the LoadInvoke program.
// Compile this class using "csc /t:library MyAssembly.cs"
// to build MyAssembly.dll.
using System;

public class MyAssembly
{
    public void MyMethod1()
    {
        Console.WriteLine("This is MyMethod1");
    }
    public void MyMethod2()
    {
        Console.WriteLine("This is MyMethod2");
    }
    public void MyMethod3()
    {
        Console.WriteLine("This is MyMethod3");
    }
}

This type is safe for multithreaded operations.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, 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

ADD
Show:
© 2014 Microsoft