Assembly::GetAssembly Method (Type^)
.NET Framework (current version)
Gets the currently loaded assembly in which the specified type is defined.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- type
-
Type:
System::Type^
An object representing a type in the assembly that will be returned.
| 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 namespace System; using namespace System::Reflection; void main() { // Get a Type object. Type^ t = int::typeid; // 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
Available since 1.1
Show: