Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Assembly Class
Assembly Methods
 GetAssembly Method
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Assembly..::.GetAssembly Method

Updated: November 2007

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

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

Visual Basic (Declaration)
Public Shared Function GetAssembly ( _
    type As Type _
) As Assembly
Visual Basic (Usage)
Dim type As Type
Dim returnValue As [Assembly]

returnValue = Assembly.GetAssembly(type)
C#
public static Assembly GetAssembly(
    Type type
)
Visual C++
public:
static Assembly^ GetAssembly(
    Type^ type
)
J#
public static Assembly GetAssembly(
    Type type
)
JScript
public static function GetAssembly(
    type : Type
) : Assembly

Parameters

type
Type: System..::.Type

A Type object representing a class in the assembly that will be returned.

Return Value

Type: System.Reflection..::.Assembly

The assembly in which the specified class is defined.

ExceptionCondition
ArgumentNullException

type is nullNothingnullptra null reference (Nothing in Visual Basic).

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 of a specified class.

Visual Basic
    Dim SampleAssembly As [Assembly]
    ' Instantiate a target object.
    Dim Integer1 As New Int32()
    Dim Type1 As Type
    ' Set the Type instance to the target class type.
    Type1 = Integer1.GetType()
    ' Instantiate an Assembly class to the assembly housing the Integer type.  
    SampleAssembly = [Assembly].GetAssembly(Integer1.GetType())
    ' Gets the location of the assembly using file: protocol.
    Console.WriteLine(("CodeBase=" + SampleAssembly.CodeBase))
End Sub

C#
Assembly SampleAssembly;
// Instantiate a target object.
Int32 Integer1 = new Int32();
Type Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.  
SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
// Gets the location of the assembly using file: protocol.
Console.WriteLine("CodeBase=" + SampleAssembly.CodeBase);

Visual C++
Assembly^ SampleAssembly;
// Instantiate a target object.
Int32 Integer1(0);
Type^ Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.  
SampleAssembly = Assembly::GetAssembly( Integer1.GetType() );
// Gets the location of the assembly using file: protocol.
Console::WriteLine( "CodeBase= {0}", SampleAssembly->CodeBase );

JScript
var SampleAssembly : Assembly;
// Instantiate a target object.
var Integer1 : Int32 = 0;
var Type1 : Type;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.  
SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
// Gets the location of the assembly using file: protocol.
Console.WriteLine("CodeBase=" + SampleAssembly.CodeBase);

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker