If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

.NET Framework General: What is the global assembly cache?

Q: What is the global assembly cache?

A:

Definition

Each computer on which the common language runtime is installed has a machine-wide code cache called the 'Global Assembly Cache'. The global assembly cache (or GAC as it is commonly known) stores assemblies specifically designated to be shared by several applications on the computer. The global assembly cache is located in 'Windows/WinNT' directory and inherits the directory's access control list that administrators have used to protect the folder.

Assemblies installed in GAC should adhere to a specific versioning scheme that will allow them for side-by-side execution (multiple versions of the same assembly can be maintained in the GAC) of different code versions.

Shared Assemblies including all the important .NET System assemblies implementing the Framework Class Library reside within GAC. The GAC was originally called Fusion Cache and is implemented using Fusion.dll in .NET Framework.

Assemblies placed in the GAC must have the same assembly name and file name (not including the file name extension). For example, an assembly with the assembly name of 'myAssembly' must have a file name of either 'myAssembly.exe' or 'myAssembly.dll'.

Scenarios for installing Assemblies in GAC

There are multiple reasons why an assembly should be installed in GAC:

File Security:

Administrators usually protect the 'Windows/WinNT' directory using an access control list (ACL) to control access. Because the GAC is located in 'Windows/WinNT' folder, this means that the GAC folder inherits the access rights from the 'Windows/WinNT' folder, and only administrators can modify the contents of the GAC. This will ensure that assemblies that are installed in GAC are not being accidentally removed/modified by in-experienced users.

Shared Location:

GAC acts as a common place for installing assemblies that are shared by multiple applications on the same machine. A common misconception is that in order to make the .NET assemblies available to COM InterOp or to the unmanaged code, the assemblies should be installed in GAC. However, this does not mandate installing assemblies in the GAC. Only those assemblies that are shared with other applications on the same machine should be installed in GAC.

Side-by-Side versioning:

Side-by-side execution means having the ability to install and use multiple versions of the same assembly. In simple words side-by-side versioning means having the same assembly present with multiple versions but with the same name. GAC can contain multiple copies of the same assembly with different versions, which allows a robust support for versioning in the Common Language Runtime.

As an additional search location:

When an assembly needs to be loaded by the Common Language Runtime, the CLR first checks the GAC for the assembly.

Pre-Requisites for installing an assembly in GAC

To install an assembly in GAC, the assembly must be signed with a strong name.

Originally Posted by .NET Framework Documentation

A strong name consists of the assembly's identity — its simple text name, version number, and culture information (if provided) — plus a public key and a digital signature. It is generated from an assembly file (the file that contains the assembly manifest, which in turn contains the names and hashes of all the files that make up the assembly), using the corresponding private key.

In order to help assemblies to sign with a string name, one can use the Strong Name Tool. Further information can also be found in the following article.