Home      Discussion      Topics      Dictionary      Almanac
Signup       Login
Global Assembly Cache

Global Assembly Cache

Overview
The Global Assembly Cache or GAC is a machine-wide .NET assemblies cache
Cache
In computer science, a cache is a collection of data duplicating original values stored elsewhere or computed earlier, where the original data is expensive to fetch or to compute, compared to the cost of reading the cache. In other words, a cache is a temporary storage area where frequently...

 for Microsoft
Microsoft
Microsoft Corporation is a multinational computer technology corporation that develops, manufactures, licenses, and supports a wide range of software products for computing devices...

's CLR
Common Language Runtime
The Common Language Runtime is a core component of Microsoft's .NET initiative. It is Microsoft's implementation of the Common Language Infrastructure standard, which defines an execution environment for program code...

 platform
Platform (computing)
In computing, a platform describes some sort of hardware architecture or software framework , that allows software to run...

. The approach of having a specially controlled central repository addresses the shared library concept and helps to avoid pitfalls of other solutions that lead to drawbacks like DLL hell
DLL hell
In computing, DLL hell is a colloquial term for the complications that arise when working with dynamic link libraries used with Microsoft Windows operating systems, particularly legacy 16-bit editions....

.

Assemblies that should be used by all applications can be put in the global assembly cache.
Discussion
Ask a question about 'Global Assembly Cache'
Start a new discussion about 'Global Assembly Cache'
Answer questions from other users
Full Discussion Forum
 
Encyclopedia
The Global Assembly Cache or GAC is a machine-wide .NET assemblies cache
Cache
In computer science, a cache is a collection of data duplicating original values stored elsewhere or computed earlier, where the original data is expensive to fetch or to compute, compared to the cost of reading the cache. In other words, a cache is a temporary storage area where frequently...

 for Microsoft
Microsoft
Microsoft Corporation is a multinational computer technology corporation that develops, manufactures, licenses, and supports a wide range of software products for computing devices...

's CLR
Common Language Runtime
The Common Language Runtime is a core component of Microsoft's .NET initiative. It is Microsoft's implementation of the Common Language Infrastructure standard, which defines an execution environment for program code...

 platform
Platform (computing)
In computing, a platform describes some sort of hardware architecture or software framework , that allows software to run...

. The approach of having a specially controlled central repository addresses the shared library concept and helps to avoid pitfalls of other solutions that lead to drawbacks like DLL hell
DLL hell
In computing, DLL hell is a colloquial term for the complications that arise when working with dynamic link libraries used with Microsoft Windows operating systems, particularly legacy 16-bit editions....

.

Shared location


Assemblies that should be used by all applications can be put in the global assembly cache. For example, if all applications should use an assembly located in the global assembly cache, a version policy statement can be added to the Machine.config file that redirects references to the assembly.

Requirements


Assemblies residing in the GAC must adhere to a specific versioning scheme which allows for side-by-side execution of different code versions. Specifically, such assembles must be strong named.

Usage


gacutil.exe is the .NET utility used to work with the GAC.

One can check the availability of a shared assembly in GAC by using the command:
gacutil.exe /l 


One can register a shared assembly in the GAC by using the command:
gacutil.exe /i 


Or by dropping an assembly file into the following location using the GUI:
%windir%\assembly\


Other options for this utility will be briefly described if you use the /? flag, i.e.:
gacutil.exe /?

Example of use


A computer has two .NET assemblies both named AssemblyA, but one is version 1.0 and the other is version 2.0. Since it is required that both be compiled to a file named AssemblyA, they cannot exist in the same directory within the FAT32
File Allocation Table
File Allocation Table or FAT is a computer file system architecture now widely used on most computer systems and most memory cards, such as those used with digital cameras.It was developed by Bill Gates and Marc McDonald during 1976–1977....

 file system
File system
In computing, a file system is a method for storing and organizing computer files and the data they contain to make it easy to find and access them...

. Instead, the virtual file system of the GAC can be used by programs that need to use each version of the assembly specifically.

Implementation


The GAC as a construct does not actually exist within the Windows OS. It is implemented and managed by the .NET Framework. The folder within %systemroot% named assembly contains all globally-available assemblies with managed filenames so that the version and public key tokens can be included. Each version can therefore exist within the same location and be called without requiring subsequent versions to preserve code entry point locations as usual. Explorer allows the drag-and-drop installation of assemblies into this folder only if they would otherwise be permitted to be installed from the command line.

A calling application may specify specific versions of an assembly when referencing them, so the Common Language Runtime
Common Language Runtime
The Common Language Runtime is a core component of Microsoft's .NET initiative. It is Microsoft's implementation of the Common Language Infrastructure standard, which defines an execution environment for program code...

 can simply refer to the filename to use the correct one.

Pitfalls


The Global Assembly Cache mechanism helps to avoid older DLL hell
DLL hell
In computing, DLL hell is a colloquial term for the complications that arise when working with dynamic link libraries used with Microsoft Windows operating systems, particularly legacy 16-bit editions....

, but it still has some drawbacks, as for example:
  • By default, applications will only run with the version of the .NET Framework
    .NET Framework
    The Microsoft .NET Framework is a software framework that can be installed on computers running Microsoft Windows operating systems. It includes a large library of coded solutions to common programming problems and a virtual machine that manages the execution of programs written specifically for...

     used to compile it, which can cause the application to fail on machines with newer versions of the .NET Framework installed — even when the application would normally run properly with the newer version.
  • It is sometimes necessary to use Conditional compilation if some of the core .NET calls (used in the application) are only supported for some versions of the framework.
  • .NET applications that rely on native code risk incompatibilities, even with the GAC mechanism.
  • Every assembly that is added to the GAC must be strongly named
    Strong key
    Strong Key is a naming convention used in computer programming. There can be more than one component with the same naming, but with different versions. This can lead to many conflicts...

    . The process of making an assembly "strongly named" can be quite painful in some situations. For example, if an assembly depends on another assembly that is not strongly named, it can not be registered in the GAC. In cases where the code of the 3rd party assembly is not in the programmer's propriety, transforming the assembly to be strongly named can in fact be impossible.

External links