.NET
GAC
Global Assembly Cache
Software Development
Microsoft

What is the GAC in .NET?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The Global Assembly Cache (GAC) is a central repository for .NET assemblies that are shared across multiple applications on a computer. The concept of the GAC was introduced with the .NET Framework to provide a way for common libraries to be easily accessible without the need for multiple copies across different application directories.

Purpose of the GAC

The GAC serves several critical functions:

  1. Versioning Control: It permits multiple versions of the same library to coexist, thus preventing the "DLL Hell" problem where applications could break due to incompatible library versions.
  2. Shared Libraries: Assemblies that are intended for shared use across different applications can be stored in the GAC, promoting reusability and reducing redundancy.
  3. Security and Identity: GAC ensures assemblies have a strong name, providing security by requiring that libraries are uniquely identified.

How the GAC Works

Strongly Named Assemblies

To be stored in the GAC, assemblies must have a strong name. A strong name consists of the assembly’s identity — which includes its simple text name, version number, culture information (if provided) — plus a public key and a digital signature generated based on the assembly's contents. This ensures that even if the assembly's contents change, its identity remains unique and verifiable.

Installing Assemblies in the GAC

To install an assembly, developers typically use tools like:

  • GACUtil: This command-line utility is used for installing and managing assemblies in the GAC.
    • Example command to add an assembly:
  • Limited to .NET Framework: The concept of GAC is specific to .NET Framework and is not applicable to .NET Core or .NET 5/6+.
  • Admin Rights Required: Installing or removing assemblies in the GAC requires administrative access.
  • Strong Names Only: Only strongly named assemblies can be placed in the GAC, potentially requiring additional setup like key pair generation.

Course illustration
Course illustration

All Rights Reserved.