Global Assembly Cache (GAC)

Understanding and Managing Assemblies in the .NET Framework

What is the Global Assembly Cache?

The Global Assembly Cache (GAC) is a repository used by the .NET Framework to store assemblies that are shared by multiple applications. It allows for versioning and makes assemblies accessible to any application that needs them, preventing naming conflicts and improving system stability by isolating application dependencies.

When you install an assembly into the GAC, it becomes available to all applications on the machine that are configured to use that specific version of the assembly. This is particularly useful for libraries and components that are intended to be used by many applications, such as runtime libraries provided by Microsoft or third-party shared components.

Key Concepts

Benefits of Using the GAC

Managing the GAC

The primary tool for interacting with the GAC is the Global Assembly Cache Tool (gacutil.exe). This tool allows you to install, uninstall, and list assemblies in the GAC.

Using gacutil.exe

gacutil.exe is typically located in the .NET Framework SDK directory. You will need to run it from a command prompt with administrator privileges.

Common gacutil.exe Commands:

Important: Always ensure you have the correct assembly name, including its full version and public key token, when uninstalling. Incorrect commands can lead to system instability.

GAC Viewer (shfusion.dll)

You can also view the GAC using the GAC Viewer. In Windows Explorer, navigate to %SystemRoot%\assembly. This folder displays assemblies with an "Assembly name," "Version," and "Culture" structure. You can also access it by running shfusion.dll (e.g., regsvr32 shfusion.dll then browse to %SystemRoot%\assembly, or directly navigate to %SystemRoot%\assembly).

When to Use the GAC

The GAC is generally recommended for:

For assemblies specific to a single application, it's usually better to deploy them alongside that application (e.g., in the application's bin directory) to avoid unnecessary complexity and potential versioning conflicts.

Considerations and Best Practices