.NET Framework Reflection What is an Assembly?

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


Assemblies are the building block of any Common Language Runtime (CLR) application. Every type you define, together with its methods, properties and their bytecode, is compiled and packaged inside an Assembly.

using System.Reflection;

Assembly assembly = this.GetType().Assembly;   

Assemblies are self-documenting: they do not only contain types, methods and their IL code, but also the Metadata necessary to inspect and consume them, both at compile and runtime:

Assembly assembly = Assembly.GetExecutingAssembly();

foreach (var type in assembly.GetTypes())

Assemblies have names which describes their full, unique identity:

// Will print: "mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"

If this name includes a PublicKeyToken, it is called a strong name. Strong-naming an assembly is the process of creating a signature by using the private key that corresponds to the public key distributed with the assembly. This signature is added to the Assembly manifest, which contains the names and hashes of all the files that make up the assembly, and its PublicKeyToken becomes part of the name. Assemblies that have the same strong name should be identical; strong names are used in versioning and to prevent assembly conflicts.

Got any .NET Framework Question?