C# Domain Assembly Details

In the .NET Framework, an assembly serves as a fundamental building block of a Common Language Runtime (CLR) application. It is a unit of deployment and versioning, containing executable code, type definitions, and other resources. Assemblies are self-describing, meaning they contain metadata that describes the types, members, and other entities within the assembly.

System.Reflection namespace

The System.Reflection namespace provides types that allow you to retrieve information about assemblies, modules, members, parameters, and other entities in managed code by examining their metadata. This namespace is essential for performing reflection, which enables runtime inspection and manipulation of types and their members.

System.Reflection.Assembly

We use the AppDomain.GetAssemblies method to retrieve an array of Assembly objects representing the assemblies currently loaded into an application domain.

AppDomain _appDomain = null; System.Reflection.Assembly[] myAssemblies = null; System.Reflection.Assembly myAssembly = null; _appDomain = AppDomain.CurrentDomain; myAssemblies = _appDomain.GetAssemblies();

Use the Assembly class to load assemblies, to explore the metadata and constituent parts of assemblies, to discover the types contained in assemblies, and to create instances of those types. The following C# program retrieves the assemblies that have been loaded into the execution context of this application domain.

Full Source C#
using System; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { AppDomain _appDomain = null; System.Reflection.Assembly[] myAssemblies = null; System.Reflection.Assembly myAssembly = null; _appDomain = AppDomain.CurrentDomain; myAssemblies = _appDomain.GetAssemblies(); foreach (System.Reflection.Assembly myAssembly_loopVariable in myAssemblies) { myAssembly = myAssembly_loopVariable; MessageBox.Show (myAssembly.FullName); } } } }

Conclusion

Using the Assembly class and the System.Reflection namespace, you can work with assemblies, explore their metadata, discover types, and create instances of those types dynamically. This opens up possibilities for tasks such as plugin systems, runtime code generation, and other advanced scenarios that require dynamic loading and manipulation of types and assemblies.