Export (0) Print
Expand All

Assembly Class

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

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

[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ComVisibleAttribute(true)]
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Unrestricted = true)]
public abstract class Assembly : _Assembly, 
	IEvidenceFactory, ICustomAttributeProvider, ISerializable

The Assembly type exposes the following members.

  NameDescription
Protected methodAssemblyInitializes a new instance of the Assembly class.
Top

  NameDescription
Public propertyCodeBaseGets the location of the assembly as specified originally, for example, in an AssemblyName object.
Public propertySupported in .NET for Windows Store appsCustomAttributesGets a collection that contains this assembly's custom attributes.
Public propertySupported in .NET for Windows Store appsDefinedTypesGets a collection of the types defined in this assembly.
Public propertySupported by Portable Class LibraryEntryPointGets the entry point of this assembly.
Public propertyEscapedCodeBaseGets the URI, including escape characters, that represents the codebase.
Public propertyEvidenceGets the evidence for this assembly.
Public propertySupported in .NET for Windows Store appsExportedTypesGets a collection of the public types defined in this assembly that are visible outside the assembly.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsFullNameGets the display name of the assembly.
Public propertyGlobalAssemblyCacheGets a value indicating whether the assembly was loaded from the global assembly cache.
Public propertyHostContextGets the host context with which the assembly was loaded.
Public propertyImageRuntimeVersionGets a string representing the version of the common language runtime (CLR) saved in the file containing the manifest.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsIsDynamicGets a value that indicates whether the current assembly was generated dynamically in the current process by using reflection emit.
Public propertyIsFullyTrustedGets a value that indicates whether the current assembly is loaded with full trust.
Public propertyLocationGets the full path or UNC location of the loaded file that contains the manifest.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsManifestModuleGets the module that contains the manifest for the current assembly.
Public propertySupported in .NET for Windows Store appsModulesGets a collection that contains the modules in this assembly.
Public propertyPermissionSetGets the grant set of the current assembly.
Public propertyReflectionOnlyGets a Boolean value indicating whether this assembly was loaded into the reflection-only context.
Public propertySecurityRuleSetGets a value that indicates which set of security rules the common language runtime (CLR) enforces for this assembly.
Top

  NameDescription
Public methodSupported by the XNA FrameworkCreateInstance(String)Locates the specified type from this assembly and creates an instance of it using the system activator, using case-sensitive search.
Public methodCreateInstance(String, Boolean)Locates the specified type from this assembly and creates an instance of it using the system activator, with optional case-sensitive search.
Public methodCreateInstance(String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])Locates the specified type from this assembly and creates an instance of it using the system activator, with optional case-sensitive search and having the specified culture, arguments, and binding and activation attributes.
Public methodStatic memberCreateQualifiedNameCreates the name of a type qualified by the display name of its assembly.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryEqualsDetermines whether this assembly and the specified object are equal. (Overrides Object.Equals(Object).)

In XNA Framework 3.0, this member is inherited from Object.Equals(Object).


In Portable Class Library Portable Class Library, this member is inherited from Object.Equals(Object).
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodStatic memberGetAssemblyGets the currently loaded assembly in which the specified class is defined.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryGetCallingAssemblyReturns the Assembly of the method that invoked the currently executing method.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetCustomAttributes(Boolean)Gets all the custom attributes for this assembly.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetCustomAttributes(Type, Boolean)Gets the custom attributes for this assembly as specified by type.
Public methodGetCustomAttributesDataReturns information about the attributes that have been applied to the current Assembly, expressed as CustomAttributeData objects.
Public methodStatic memberGetEntryAssemblyGets the process executable in the default application domain. In other application domains, this is the first executable that was executed by AppDomain.ExecuteAssembly.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryGetExecutingAssemblyGets the assembly that contains the code that is currently executing.
Public methodSupported by Portable Class LibraryGetExportedTypesGets the public types defined in this assembly that are visible outside the assembly.
Public methodGetFileGets a FileStream for the specified file in the file table of the manifest of this assembly.
Public methodGetFiles()Gets the files in the file table of an assembly manifest.
Public methodGetFiles(Boolean)Gets the files in the file table of an assembly manifest, specifying whether to include resource modules.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetHashCodeReturns the hash code for this instance. (Overrides Object.GetHashCode().)

In XNA Framework 3.0, this member is inherited from Object.GetHashCode().


In Portable Class Library Portable Class Library, this member is inherited from Object.GetHashCode().
Public methodGetLoadedModules()Gets all the loaded modules that are part of this assembly.
Public methodGetLoadedModules(Boolean)Gets all the loaded modules that are part of this assembly, specifying whether to include resource modules.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetManifestResourceInfoReturns information about how the given resource has been persisted.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetManifestResourceNamesReturns the names of all the resources in this assembly.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetManifestResourceStream(String)Loads the specified manifest resource from this assembly.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetManifestResourceStream(Type, String)Loads the specified manifest resource, scoped by the namespace of the specified type, from this assembly.
Public methodGetModuleGets the specified module in this assembly.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetModules()Gets all the modules that are part of this assembly.
Public methodGetModules(Boolean)Gets all the modules that are part of this assembly, specifying whether to include resource modules.
Public methodSupported by the XNA FrameworkSupported in .NET for Windows Store appsGetName()Gets an AssemblyName for this assembly.
Public methodSupported by the XNA FrameworkGetName(Boolean)Gets an AssemblyName for this assembly, setting the codebase as specified by copiedName.
Public methodGetObjectDataGets serialization information with all of the data needed to reinstantiate this assembly.
Public methodGetReferencedAssembliesGets the AssemblyName objects for all the assemblies referenced by this assembly.
Public methodSupported by the XNA FrameworkGetSatelliteAssembly(CultureInfo)Gets the satellite assembly for the specified culture.
Public methodSupported by the XNA FrameworkGetSatelliteAssembly(CultureInfo, Version)Gets the specified version of the satellite assembly for the specified culture.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetType()Gets the Type of the current instance. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetType(String)Gets the Type object with the specified name in the assembly instance.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetType(String, Boolean)Gets the Type object with the specified name in the assembly instance and optionally throws an exception if the type is not found.
Public methodGetType(String, Boolean, Boolean)Gets the Type object with the specified name in the assembly instance, with the options of ignoring the case, and of throwing an exception if the type is not found.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetTypesGets the types defined in this assembly.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryIsDefinedIndicates whether or not a specified attribute has been applied to the assembly.
Public methodStatic memberSupported by the XNA FrameworkSupported in .NET for Windows Store appsLoad(AssemblyName)Loads an assembly given its AssemblyName.
Public methodStatic memberLoad(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 methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryLoad(String)Loads an assembly given the long form of its name.
Public methodStatic memberLoad(AssemblyName, Evidence) Obsolete. Loads an assembly given its AssemblyName. The assembly is loaded into the domain of the caller using the supplied evidence.
Public methodStatic memberLoad(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 methodStatic memberLoad(String, Evidence) Obsolete. Loads an assembly given its display name, loading the assembly into the domain of the caller using the supplied evidence.
Public methodStatic memberLoad(Byte[], Byte[], Evidence) 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 methodStatic memberLoad(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 methodStatic memberLoadFile(String)Loads the contents of an assembly file on the specified path.
Public methodStatic memberLoadFile(String, Evidence) Obsolete. Loads an assembly given its path, loading the assembly into the domain of the caller using the supplied evidence.
Public methodStatic memberSupported by the XNA FrameworkLoadFrom(String)Loads an assembly given its file name or path.
Public methodStatic memberLoadFrom(String, Evidence) Obsolete. Loads an assembly given its file name or path and supplying security evidence.
Public methodStatic memberLoadFrom(String, Byte[], AssemblyHashAlgorithm)Loads an assembly given its file name or path, hash value, and hash algorithm.
Public methodStatic memberLoadFrom(String, Evidence, Byte[], AssemblyHashAlgorithm) Obsolete. Loads an assembly given its file name or path, security evidence, hash value, and hash algorithm.
Public methodLoadModule(String, Byte[])Loads the module, internal to this assembly, with a common object file format (COFF)-based image containing an emitted module, or a resource file.
Public methodLoadModule(String, Byte[], Byte[])Loads the module, internal to this assembly, with a common object file format (COFF)-based image containing an emitted module, or a resource file. The raw bytes representing the symbols for the module are also loaded.
Public methodStatic memberLoadWithPartialName(String) Obsolete. Loads an assembly from the application directory or from the global assembly cache using a partial name.
Public methodStatic memberLoadWithPartialName(String, Evidence) Obsolete. Loads an assembly from the application directory or from the global assembly cache using a partial name. The assembly is loaded into the domain of the caller using the supplied evidence.
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberReflectionOnlyLoad(Byte[])Loads the assembly from a common object file format (COFF)-based image containing an emitted assembly. The assembly is loaded into the reflection-only context of the caller's application domain.
Public methodStatic memberReflectionOnlyLoad(String)Loads an assembly into the reflection-only context, given its display name.
Public methodStatic memberReflectionOnlyLoadFromLoads an assembly into the reflection-only context, given its path.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns the full name of the assembly, also known as the display name. (Overrides Object.ToString().)
Public methodStatic memberUnsafeLoadFromLoads an assembly into the load-from context, bypassing some security checks.
Top

  NameDescription
Public eventModuleResolveOccurs when the common language runtime class loader cannot resolve a reference to an internal module of an assembly through normal means.
Top

  NameDescription
Public operatorStatic memberEqualityIndicates whether two Assembly objects are equal.
Public operatorStatic memberInequalityIndicates whether two Assembly objects are not equal.
Top

  NameDescription
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttribute(Type)Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified assembly. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttribute(Type)Overloaded. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttribute<T>()Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified assembly. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttribute<T>()Overloaded. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttributes()Overloaded. Retrieves a collection of custom attributes that are applied to a specified assembly. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttributes()Overloaded. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttributes(Type)Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified assembly. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttributes(Type)Overloaded. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttributes<T>()Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified assembly. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttributes<T>()Overloaded. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsIsDefined(Type)Overloaded. Indicates whether custom attributes of a specified type are applied to a specified assembly. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsIsDefined(Type)Overloaded. (Defined by CustomAttributeExtensions.)
Top

  NameDescription
Explicit interface implemetationPrivate method_Assembly.GetTypeReturns the type of the current instance.
Top

Use the Assembly class to load assemblies, to explore the metadata and constituent parts of assemblies, to discover the types contained in assemblies, and to create instances of those types.

To get an array of Assembly objects representing the assemblies currently loaded into an application domain (for example, the default application domain of a simple project), use the AppDomain.GetAssemblies method.

To load assemblies dynamically, the Assembly class provides the following static methods (Shared methods in Visual Basic). Assemblies are loaded into the application domain where the load operation occurs.

  • The recommended way to load assemblies is to use the Load method, which identifies the assembly to be loaded by its display name (for example, "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"). The search for the assembly follows the rules described in How the Runtime Locates Assemblies.

  • The ReflectionOnlyLoad and ReflectionOnlyLoadFrom methods enable you to load an assembly for reflection, but not for execution. For example, an assembly that targets a 64-bit platform can be examined by code that is running on a 32-bit platform.

  • The LoadFile and LoadFrom methods are provided for rare scenarios in which an assembly must be identified by path.

To get an Assembly object for the currently executing assembly, use the GetExecutingAssembly method.

Many members of the Assembly class provide information about an assembly. For example:

  • The GetName method returns an AssemblyName object that provides access to the parts of the assembly display name.

  • The GetCustomAttributes method lists the attributes applied to the assembly.

  • The GetFiles method provides access to the files in the assembly manifest.

  • The GetManifestResourceNames method provides the names of the resources in the assembly manifest.

The GetTypes method lists all the types in the assembly. The GetExportedTypes method lists the types that are visible to callers outside the assembly. The GetType method can be used to search for a particular type in the assembly. The CreateInstance method can be used to search for and create instances of types in the assembly.

For more information on assemblies, see Application Domains and Assemblies.

The following code example shows how to obtain the currently executing assembly, create an instance of a type contained in that assembly, and invoke one of the type's methods with late binding. For this purpose, the code example defines a class named Example, with a method named SampleMethod. The constructor of the class accepts an integer, which is used to compute the return value of the method.

The code example also demonstrates the use of the GetName method to obtain an AssemblyName object that can be used to parse the full name of the assembly. The example displays the version number of the assembly, the CodeBase property, and the EntryPoint property.

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

[assembly:AssemblyVersionAttribute("1.0.2000.0")]

public class Example
{
    private int factor;
    public Example(int f)
    {
        factor = f;
    }

    public int SampleMethod(int x) 
    { 
        Console.WriteLine("\nExample.SampleMethod({0}) executes.", x);
        return x * factor;
    }

    public static void Main()
    {
        Assembly assem = typeof(Example).Assembly;

        Console.WriteLine("Assembly Full Name:");
        Console.WriteLine(assem.FullName);

        // The AssemblyName type can be used to parse the full name.
        AssemblyName assemName = assem.GetName();
        Console.WriteLine("\nName: {0}", assemName.Name);
        Console.WriteLine("Version: {0}.{1}", 
            assemName.Version.Major, assemName.Version.Minor);

        Console.WriteLine("\nAssembly CodeBase:");
        Console.WriteLine(assem.CodeBase);

        // Create an object from the assembly, passing in the correct number 
        // and type of arguments for the constructor.
        Object o = assem.CreateInstance("Example", false, 
            BindingFlags.ExactBinding, 
            null, new Object[] { 2 }, null, null);

        // Make a late-bound call to an instance method of the object.    
        MethodInfo m = assem.GetType("Example").GetMethod("SampleMethod");
        Object ret = m.Invoke(o, new Object[] { 42 });
        Console.WriteLine("SampleMethod returned {0}.", ret);

        Console.WriteLine("\nAssembly entry point:");
        Console.WriteLine(assem.EntryPoint);
    }
}

/* This code example produces output similar to the following:

Assembly Full Name:
source, Version=1.0.2000.0, Culture=neutral, PublicKeyToken=null

Name: source
Version: 1.0

Assembly CodeBase:
file:///C:/sdtree/AssemblyClass/cs/source.exe

Example.SampleMethod(42) executes.
SampleMethod returned 84.

Assembly entry point:
Void Main()
 */

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

This type is thread safe.

Show:
© 2014 Microsoft