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 Shared Function GetAssembly (
	type As Type
) As Assembly


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

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.

Imports System.Reflection

Module Example
   Public Sub Main()
      ' Get a Type object.
      Dim t As Type = GetType(Integer)
      ' Instantiate an Assembly class to the assembly housing the Integer type.
      Dim assem As Assembly = 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)
   End Sub
End Module
' The example displays output like the following:
'    Name: mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089
'    CodeBase: file:'/C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll


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

.NET Framework
Available since 1.1
Return to top