SIGN UP MEMBER LOGIN:    
ARTICLE

Indepths of Global Assembly Cache

Posted by Nirlep Kaur Articles | C# Assemblies November 18, 2005
This article gives an indepth knowledge of working of global assembly cache.
Reader Level:

Each computer where the common language runtime (CLR) is installed has a global assembly cache. Abbreviated as GAC, the Global Assembly Cache is a machine-wide store used to hold assemblies that are intended to be shared by several applications on the machine. In the .NET Framework, the Global Assembly Cache acts as the central place for registering assemblies. The GAC was originally called the Fusion cache and is implemented in Fusion.dll.

We can deploy an assembly into the Global Assembly Cache in various ways. An installer that works with the Global Assembly Cache can be used. This is the best way to install assemblies into the Global Assembly Cache. The next way is to use a developer tool called the Global Assembly Cache tool that is available in the .NET Framework SDK. You can also drag assemblies into the Global Assembly Cache using the Windows Explorer.

Advantages of using GAC are:

  1. Strong name signature verification. All shared assemblies must have strong name signatures. These signature are verified when the assembly is installed into the gac. Once verified the signatures are not verified each time the assembly is referenced. In contrast, shared assemblies deployed outside the assembly have their signatures verified each time the assembly is loaded.

  2. Performance: CLR to look into the GAC first when resolving an Assembly reference.  If it doesn't find the requested assembly in the GAC then it looks in the application directory and follows the rest of the probing logic algorithm.  Clearly there is a performance gain by putting the assembly in the first place to be searched.

  3. Deploying bug fixes. Administrators can use the gac to deploy bug fixes intended to be picked up by all applications. By deploying the fix to the gac and stating the appropriate version policy in the machine configuration file, an admin can ensure that all applications on the machine will begin to use the fix.

Despite these benefits, using the gac has one distinct disadvantage: It increases the complexity of installing and uninstalling your assembly. Specifically, the ability to install an application by just copying files, or the ability to uninstall it by just deleting a directory is lost.

Viewing actual structure of GAC

When you look at the GAC directory in explorer, looks like all the assembly files are directly under GAC directory, but actually it's not. If you go to the GAC directory in a dos window, you can see that GAC contains subdirectories and each assembly file has its own individual subdirectory. The reason that GAC directory looks differently from explorer is that you actually look at files from fusion shell, which makes GAC information easy to read. To view the physical file structure of GAC, add a binary value named 'DisableCacheViewer' to the registry key HKLM\Software\Microsoft\Fusion and set it to a non-zero value.

Specify space used by GAC

Navigate to the GAC directory, C:\winnt\Assembly in explorer. In the tools menu select the cache properties; in the window displayed you can set the memory limit in MB used by the GAC.

Relocate GAC 

The default location of GAC is <%windir% >\assembly folder. This location is not configurable during the .NET Framework setup / installation. Once the .NET Framework is fully installed, it is possible to relocate the GAC to a different location. Set the registry key CacheLocation (REG_SZ) under HKLM\Software\Microsoft\Fusion to the pathname of the folder where the GAC needs to be located. . NET will create an assembly subfolder underneath the CacheLocation specified in the registry key, so you should not include assembly in the pathname specified. XCOPY the contents of your current GAC to this new location.

Login to add your contents and source code to this article
share this article :
post comment
 

I think that Fusion is the .Net laoder and it uses the GAC but Fusion is not the GAC.

Posted by Sam Hobbs Oct 18, 2011

Odd that your last paragraph is almost identical to a section in this article: http://www.codeproject.com/KB/dotnet/demystifygac.aspx No cookie for you.

Posted by james stone Oct 01, 2008

Hi,

I placed two assemblies with same functions with different versions, then did second assembly overwrite first assembly?Shall I use two assemblies side by side?

Please resolve this issue.

Thanks,

Naidu.

Posted by Naidu Maddila Nov 08, 2006
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Gauge for SharePoint
Become a Sponsor