Gets the currently loaded assembly in which the specified class is defined.
Assembly: mscorlib (in mscorlib.dll)
Syntax . . :: . Assembly
The assembly in which the specified class is defined.
Public Shared Function GetAssembly ( _
type As Type _
) As Assemblypublic static Assembly GetAssembly(
Type type
)public:
static Assembly^ GetAssembly(
Type^ type
)static member GetAssembly :
type:Type -> Assembly
Parameters
- type
- Type: System
. . :: . Type
An object representing a class in the assembly that will be returned.
Return Value
Type: System.ReflectionThe assembly in which the specified class is defined.
Exceptions
| Exception | Condition |
|---|---|
| ArgumentNullException | type is |
Remarks
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.
Examples
The following example retrieves the assembly of a specified class.
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
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);
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 );
.NET Framework Security
- ReflectionPermission
when invoked late-bound through mechanisms such as Type
. . :: . InvokeMember. Associated enumeration: ReflectionPermissionFlag. . :: . MemberAccess
Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.