.NET Assemblies

Assemblies are the fundamental building blocks of .NET applications. They are the unit of deployment, versioning, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality.

What is an Assembly?

An assembly is a compiled code library or executable. It contains:

Assemblies are typically distributed as either Dynamic Link Libraries (.dll) or executable files (.exe).

Assembly Manifest

The assembly manifest is crucial for the Common Language Runtime (CLR) to understand and manage the assembly. It provides essential information such as:

The manifest can be embedded within a single assembly file or stored in a separate file.

Types of Assemblies

Assemblies can be categorized based on their content and purpose:

Strongly Named Assemblies

A strongly named assembly is one that has a unique identity based on its name, version, culture, and a digital signature generated from a public-private key pair. This helps prevent assembly conflicts and provides better versioning control.

Strongly named assemblies are essential for creating shared assemblies that can be deployed in the Global Assembly Cache (GAC).

The Global Assembly Cache (GAC)

The GAC is a machine-wide code cache maintained by the CLR. Assemblies that are intended to be shared among multiple applications can be installed into the GAC. This allows applications to reference and use these shared assemblies without needing them to be in the application's own directory.

Only strongly named assemblies can be installed in the GAC.

Example: Referencing an Assembly

When you create a .NET project, you often add references to other assemblies (like System.dll, System.Core.dll, or custom libraries). This tells the compiler and the CLR where to find the types your code uses.


// In a C# project, adding a reference to System.Xml.dll
// would allow you to use types like XmlDocument:

using System;
using System.Xml; // This 'using' directive implies a reference to System.Xml.dll

public class DocumentProcessor
{
    public void LoadDocument(string filePath)
    {
        XmlDocument doc = new XmlDocument();
        doc.Load(filePath);
        Console.WriteLine("Document loaded successfully.");
    }
}
            

Key Concepts