What is the Global Assembly Cache (GAC)?
The Global Assembly Cache (GAC) is a machine-wide cache for .NET Framework assemblies that are specifically designated to be shared by multiple applications on a computer. It provides a centralized repository for storing and managing shared assemblies, ensuring version control and security.
In modern .NET (Core, 5+), the traditional GAC has been replaced with alternative sharing mechanisms like NuGet packages and the runtime assembly store, emphasizing application-local deployment rather than machine-wide sharing.
Key Characteristics
| Feature | Description | 
|---|---|
| Strong Naming | Assemblies must be strong-named (signed with a cryptographic key) to be installed in the GAC | 
| Side-by-Side Versioning | Multiple versions of the same assembly can coexist in the GAC | 
| Security | GAC assemblies have a higher level of trust than private assemblies | 
| Administrative Access | Installing to the GAC requires administrative privileges | 
| Centralized Management | Provides a single location for managing shared assemblies | 
GAC Locations
- .NET Framework (up to 4.0): %windir%\assembly
- .NET Framework 4.0+: %windir%\Microsoft.NET\assembly
- .NET Core/5+: No traditional GAC (uses different mechanisms)
Working with the GAC
Installing Assemblies
# Using gacutil.exe (requires .NET Framework SDK)
gacutil /i SharedLibrary.dll
# Uninstalling
gacutil /u SharedLibraryReferencing GAC Assemblies
<!-- Strong-named reference to a GAC assembly -->
<Reference Include="SharedLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />Strong Naming (Required for GAC)
// Generate key pair (using Developer Command Prompt)
// sn -k MyKeyPair.snk
// Sign the assembly in project file
<PropertyGroup>
  <SignAssembly>true</SignAssembly>
  <AssemblyOriginatorKeyFile>MyKeyPair.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>Modern Alternatives (.NET Core/5+)
Since .NET Core and .NET 5+, the GAC concept has changed:
- NuGet Packages: Primary mechanism for sharing code - <PackageReference Include="SharedLibrary" Version="1.0.0" />
- Runtime Store: For shared framework components - dotnet store --manifest packages.manifest.csproj --runtime win-x64
- Assembly Load Context: For more controlled assembly loading 
When to Use the GAC
Appropriate Use Cases
- Shared components used by multiple applications
- Common libraries across an organization
- Security-sensitive code requiring higher trust
When to Avoid
- Application-specific assemblies
- Frequently updated code
- Modern .NET Core/5+ applications
- When deployment simplicity is important
Common Issues
- Assembly Binding Redirects: Required when using different versions - <bindingRedirect oldVersion="1.0.0.0-1.9.9.9" newVersion="2.0.0.0" />
- Deployment Complexity: Requires administrative access and careful versioning 
- DLL Hell: The GAC was designed to solve “DLL Hell” but can create its own versioning challenges 
Best Practices
- For .NET Framework: Use the GAC only for truly shared components
- For .NET Core/5+: Use NuGet packages instead of the GAC
- Always strong-name assemblies intended for the GAC
- Use assembly binding redirects when needed
- Consider deployment implications when deciding to use the GAC
Test Your Knowledge
Take a quick quiz to test your understanding of this topic.