What are the different types of assemblies in .NET?

In .NET, an assembly is the fundamental unit of deployment, version control, reuse, and security. It is a compiled code library typically stored as an EXE or DLL file that contains IL (Intermediate Language) code, metadata, and resources.

Assembly Classification

.NET assemblies can be categorized in several ways:

1. By File Type

TypeDescriptionExample
Executable (.exe)Contains entry point (Main method)MyApp.exe
Library (.dll)Reusable code without entry pointMyLibrary.dll
// Executable assembly with entry point
public class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
    }
}

2. By Accessibility

TypeDescriptionAccess
Private AssemblyUsed by a single applicationApplication directory
Shared AssemblyUsed by multiple applicationsGlobal Assembly Cache (GAC)
// Private assembly reference
<Reference Include="PrivateLibrary" />

// Shared assembly reference (strong-named, in GAC)
<Reference Include="SharedLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

3. By Creation Method

TypeDescriptionUse Case
Static AssemblyCreated at compile timeNormal application development
Dynamic AssemblyCreated at runtimeCode generation, reflection
// Creating a dynamic assembly at runtime
AssemblyName assemblyName = new AssemblyName("DynamicAssembly");
AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(
    assemblyName, AssemblyBuilderAccess.Run);

4. By Composition

TypeDescriptionExample
Single-file AssemblyAll code in one fileSmall libraries
Multi-file AssemblyCode split across filesLarge frameworks
// Creating a multi-file assembly (using compiler options)
csc /target:library /out:MyAssembly.dll File1.cs File2.cs

5. By Reference Type

TypeDescriptionExample
Strongly NamedDigitally signed with a keySystem.Data.dll
RegularNot digitally signedSimple application libraries
// Strong naming an assembly
[assembly: AssemblyKeyFile("MyKey.snk")]

// In modern .NET projects
<PropertyGroup>
  <SignAssembly>true</SignAssembly>
  <AssemblyOriginatorKeyFile>MyKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

Assembly Structure

Every .NET assembly contains:

  1. Assembly Manifest: Metadata about the assembly (version, dependencies)
  2. Type Metadata: Information about types defined in the assembly
  3. IL Code: Compiled code in Intermediate Language format
  4. Resources: Embedded files (images, strings, etc.)

Assembly Loading

Assemblies are loaded into the CLR using different strategies:

  • Load-by-name: CLR searches for the assembly in predefined locations
  • Explicit loading: Using Assembly.Load() or Assembly.LoadFrom()
  • Reflection-only loading: For inspection without execution
// Explicitly loading an assembly
Assembly assembly = Assembly.LoadFrom("MyLibrary.dll");

// Creating an instance from a loaded assembly
Type type = assembly.GetType("MyLibrary.MyClass");
object instance = Activator.CreateInstance(type);

Modern .NET Assembly Considerations

In .NET Core and .NET 5+:

  • No GAC: Shared assemblies use NuGet packages instead
  • Self-contained deployment: All dependencies included with the app
  • Assembly trimming: Unused parts can be removed
  • Single-file applications: All assemblies bundled into one executable

Test Your Knowledge

Take a quick quiz to test your understanding of this topic.

Test Your .NET Knowledge

Ready to put your skills to the test? Take our interactive .NET quiz and get instant feedback on your answers.