What exactly is an Assembly in C or .NET?
Data Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.
Introduction
In the context of C# and .NET, an Assembly is a fundamental building block of any application. It represents a compiled code library used by .NET applications. These assemblies are created whenever a .NET program is built, serving as containers for the types and resources of a .NET application.
Assemblies ensure version management and facilitate the deployment of applications by conveniently combining code and resources within a single package.
Technical Overview
An assembly in .NET is the smallest unit of deployment, version control, security permissions, and reference packaging. Assemblies typically have four main characteristics:
- Versioning Information: Assemblies maintain versioning information, which helps manage changes and updates over time.
- Public Types: Assemblies encapsulate a collection of types defined in the Common Language Runtime (CLR).
- Resources: Assemblies can include resources such as strings, images, and files.
- Manifest: Assemblies contain metadata called a manifest, which includes the assembly's name, version number, culture settings, and public key if it's a strongly named assembly.
Types of Assemblies
- Static Assemblies: These are simply created when a .NET application is compiled. These are typically stored as `.dll` or `.exe` files. Static assemblies allow code reuse across multiple projects.
- Dynamic Assemblies: Unlike static assemblies, dynamic assemblies are either saved to disk or executed directly from memory. They are created programmatically at runtime and are useful for scenarios involving on-the-fly code generation.
Assembly Components
An assembly comprises several key components:
- Manifest: Contains metadata about the assembly like name, version, culture, and information about referenced assemblies.
- Type Metadata: Provides metadata about each type defined within the assembly including classes, interfaces, and value types.
- Intermediate Language (IL) Code: CPU-independent code that the CLR compiles to native machine code at runtime.
- Resources: Files that include static resources such as images and localized language strings.
Example
Here's a simple example to illustrate how an assembly is created in C#. Consider this C# code file, `HelloWorld.cs`:
- Implicit Loading: Occurs automatically when the application starts.
- Explicit Loading: Managed by code through reflection, often leveraging the `System.Reflection.Assembly` class.
Related reading
- What exactly is an open generic type in .NET?
- What exceptions does Newtonsoft.Json.DeserializeObject throw?
- What exceptions should be thrown for invalid or unexpected parameters in .NET?
- What guarantees are there on the run-time complexity Big-O of LINQ methods?
- What guarantees are there on the run-time complexity Big-O of LINQ methods?
- What happens if I remove the auto added supportedRuntime element?
- What happens if i return before the end of using statement? Will the dispose be called?
- What interfaces do all arrays implement in C?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.