Defines an Assembly, which is a reusable, versionable, and self-describing building block of a common language runtime application.
For a list of all members of this type, see Assembly Members.
System.Object
System.Reflection.Assembly
System.Reflection.Emit.AssemblyBuilder
[Visual Basic]
<Serializable>
<ClassInterface(ClassInterfaceType.AutoDual)>
Public Class Assembly
Implements IEvidenceFactory, ICustomAttributeProvider, _
ISerializable
[C#]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Assembly : IEvidenceFactory,
ICustomAttributeProvider, ISerializable
[C++]
[Serializable]
[ClassInterface(ClassInterfaceType::AutoDual)]
public __gc class Assembly : public IEvidenceFactory,
ICustomAttributeProvider, ISerializable
[JScript]
public
Serializable
ClassInterface(ClassInterfaceType.AutoDual)
class Assembly implements IEvidenceFactory,
ICustomAttributeProvider, ISerializable
Thread Safety
This type is safe for multithreaded operations.
Remarks
Assemblies provide the infrastructure that allows the runtime to fully understand the contents of an application and to enforce the versioning and dependency rules defined by the application. These concepts are crucial for solving the versioning problem and for simplifying the deployment of runtime applications.
Example
[Visual Basic]
' LoadInvoke loads MyAssembly.dll and invokes the MyMethod1 method.
' After compiling this class, run LoadInvoke.exe with MyAssembly.dll
' as the command line argument, as shown below:
' LoadInvoke Myassembly.dll
Imports System
Imports System.Reflection
Public Class LoadInvoke
Public Shared Sub Main(ByVal args() As String)
Dim a As [Assembly] = [Assembly].LoadFrom(args(0))
Dim mytypes As Type() = a.GetTypes()
Dim flags As BindingFlags = BindingFlags.NonPublic Or BindingFlags.Public Or BindingFlags.Static Or _
BindingFlags.Instance Or BindingFlags.DeclaredOnly
Dim t As Type
For Each t In mytypes
Dim mi As MethodInfo() = t.GetMethods(flags)
Dim obj As [Object] = Activator.CreateInstance(t)
Dim m As MethodInfo
For Each m In mi
m.Invoke(obj, Nothing)
Next m
Next t
End Sub 'Main
End Class 'LoadInvoke
[C#]
// LoadInvoke loads MyAssembly.dll and invokes the MyMethod1 method.
// After compiling this class, run LoadInvoke.exe with MyAssembly.dll
// as the command line argument, as shown below:
// LoadInvoke Myassembly.dll
using System;
using System.Reflection;
public class LoadInvoke
{
public static void Main(string[] args)
{
Assembly a = Assembly.LoadFrom(args[0]);
Type[] mytypes = a.GetTypes();
BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
foreach(Type t in mytypes)
{
MethodInfo[] mi = t.GetMethods(flags);
Object obj = Activator.CreateInstance(t);
foreach(MethodInfo m in mi)
{
m.Invoke(obj, null);
}
}
}
}
[C++]
// LoadInvoke loads MyAssembly.dll and invokes the MyMethod1 method.
// After compiling this class, run LoadInvoke.exe with MyAssembly.dll
// as the command line argument, as shown below:
// LoadInvoke Myassembly.dll
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;
int main() {
String* args[] = Environment::GetCommandLineArgs();
Assembly* a = Assembly::LoadFrom(args[1]);
Type* mytypes[] = a->GetTypes();
BindingFlags flags = static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Public |
BindingFlags::Static | BindingFlags::Instance | BindingFlags::DeclaredOnly);
System::Collections::IEnumerator* myEnum = mytypes->GetEnumerator();
while (myEnum->MoveNext()) {
Type* t = __try_cast<Type*>(myEnum->Current);
MethodInfo* mi[] = t->GetMethods(flags);
Object* obj = Activator::CreateInstance(t);
System::Collections::IEnumerator* myEnum = mi->GetEnumerator();
while (myEnum->MoveNext()) {
MethodInfo* m = __try_cast<MethodInfo*>(myEnum->Current);
m->Invoke(obj, 0);
}
}
}
[Visual Basic]
' Use this class with the LoadInvoke program.
' Compile this class using vbc /t:library MyAssembly.vb
' to obtain MyAssembly.dll.
Imports System
Imports Microsoft.VisualBasic
Public Class MyAssembly
Public Sub MyMethod1()
Console.WriteLine("Invoking MyAssembly.MyMethod1")
End Sub 'MyMethod1
End Class 'MyAssembly
[C#]
// Use this class with the LoadInvoke program.
// Compile this class using csc /t:library MyAssembly.cs
// to obtain MyAssembly.dll.
using System;
public class MyAssembly
{
public void MyMethod1()
{
Console.WriteLine("Invoking MyAssembly.MyMethod1");
}
}
[C++]
// Use this class with the LoadInvoke program.
// Compile this class using csc /t:library MyAssembly.cs
// to obtain MyAssembly.dll.
#using <mscorlib.dll>
using namespace System;
public __gc class MyAssembly
{
public:
void MyMethod1()
{
Console::WriteLine(S"Invoking MyAssembly.MyMethod1");
}
};
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Reflection
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
Assembly: Mscorlib (in Mscorlib.dll)
See Also
Assembly Members | System.Reflection Namespace