12 August 2015

The Global Assembly Cache (GAC)


  • Global - Applies to the entire machine

  • Assembly - code-libraries (DLLs)

  • Cache – Place to store things for common access



  1. GAC is a common place to store code libraries (assemblies), so they're accessible to all applications running on the machine.

  2. C:\Windows\assembly for .NET 2.0 ~ 3.5, C:\WINDOWS\Micorosoft.NET\assembly (for .NET 4.0)

  3. Normal Assemblies can be shared among multiple applications on the machine by registering them in global Assembly cache (GAC).

  4. A DLL is identified by 5 parts:


Name, Version, Architecture, Culture, Public Key.


Although the first 3 are generally the big ones.




  1. To install an assembly into GAC (as Administrator)


1) Drag and Drop


2) Use GacUtil.exe with Visual Studio Command Prompt


gacutil -i [Path][Assembly Name].dll


Note: To install an assembly into the GAC, the assembly must be strongly named. Otherwise you get an error like this: Failure adding assembly to the cache: Attempt to install an assembly without a strong name.




  1. To uninstall an assembly from GAC (as Administrator)


gacutil -u [Assembly Name], Version=1.0.0.0, PublickeyToken=7896a3567gh


Note: has no extention, .dll. Version and PublickeyToken can be omitted and be checked in GAC assembly.




  1. The only requirement for an assembly to be deployed in GAC is that it should have strong name. The CLR (Common Language Runtime) refers an assembly based on specific version mentioned by the calling application/method.

  2. The two tools related to GAC are GAC Tool (gacutil.exe) and Assembly Cache Viewer (shfusion.dll). GAC Tool is used to check for assembly existence, register a shared assembly, view and manipulate contents of GAC, etc. Being a system folder, it requires administrator privileges to be used.                                   Assembly Cache Viewer is used to display the details (version, culture, etc.) associated with the assemblies contained in the cache.

  3. GAC provides the benefits of code reuse, file security (due to its installation in ‘systemroot’ directory and hence deletion is only by users with Administrator privileges), side-by-side execution (allowing multiple versions of an assembly maintained in the same folder)

  4. Unlike in COM, there is no need for the assembly in GAC to be registered before its use. Each assembly is accessed globally without any conflict by identifying its name, version, architecture, culture and public key.

No comments: