Assembly.GetAssembly Method (Type)

 

Gets the currently loaded assembly in which the specified type is defined.

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

public static Assembly GetAssembly(
	Type type
)

Parameters

type
Type: System.Type

An object representing a type in the assembly that will be returned.

Return Value

Type: System.Reflection.Assembly

The assembly in which the specified type is defined.

Exception Condition
ArgumentNullException

type is null.

Calling this method is equivalent to retrieving the value of the Type.Assembly property. However, the Type.Assembly property typically offers superior performance.

In order to call this method, you must have a Type object, which means that the assembly in which the class is defined must already be loaded.

The following example retrieves the assembly that contains the Int32 type and displays its name and file location.

using System;
using System.Reflection;

public class Example
{
   public static void Main()
   {
      // Get a Type object.
      Type t = typeof(int);
      // Instantiate an Assembly class to the assembly housing the Integer type.
      Assembly assem = Assembly.GetAssembly(t);
      // Display the name of the assembly.
      Console.WriteLine("Name: {0}", assem.FullName);
      // Get the location of the assembly using the file: protocol.
      Console.WriteLine("CodeBase: {0}", assem.CodeBase);
   }
}
// The example displays output like the following:
//    Name: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
//    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll

ReflectionPermission

when invoked late-bound through mechanisms such as Type.InvokeMember. Associated enumeration: ReflectionPermissionFlag.MemberAccess

.NET Framework
Available since 1.1
Return to top
Show: