Global Assembly Cache
   HOME

TheInfoList



OR:

The Global Assembly Cache (GAC) is a machine-wide CLI assembly
cache Cache, caching, or caché may refer to: Places United States * Cache, Idaho, an unincorporated community * Cache, Illinois, an unincorporated community * Cache, Oklahoma, a city in Comanche County * Cache, Utah, Cache County, Utah * Cache County ...
for the
Common Language Infrastructure The Common Language Infrastructure (CLI) is an open specification and technical standard originally developed by Microsoft and standardized by ISO/IEC (ISO/IEC 23271) and Ecma International (ECMA 335) that describes executable code and a runt ...
(CLI) in Microsoft's .NET Framework. The approach of having a specially controlled central repository addresses the flaws in the
shared library In computer science, a library is a collection of non-volatile resources used by computer programs, often for software development. These may include configuration data, documentation, help data, message templates, pre-written code and subr ...
concept and helps to avoid pitfalls of other solutions that led to drawbacks like
DLL hell In computing, DLL Hell is a term for the complications that arise when one works with dynamic-link libraries (DLLs) used with Microsoft Windows operating systems, particularly legacy 16-bit editions, which all run in a single memory space. DLL Hel ...
.


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 assemblies must be strongly named.


Usage

There are two ways to interact with the GAC: the Global Assembly Cache Tool (gacutil.exe) and the Assembly Cache Viewer (shfusion.dll).


Global Assembly Cache Tool

gacutil.exe is an older command-line utility that shipped with .NET 1.1 and is still available with the .NET SDK. 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 copying an assembly file into the following location:
%windir%\assembly\
Note that for .NET 4.0 the GAC location is now:
%windir%\Microsoft.NET\assembly\
Other options for this utility will be briefly described if you use the /? flag, i.e.:
gacutil.exe /?


Assembly Cache Viewer

The newer interface, the Assembly Cache Viewer, is integrated into
Windows Explorer File Explorer, previously known as Windows Explorer, is a file manager application that is included with releases of the Microsoft Windows operating system from Windows 95 onwards. It provides a graphical user interface for accessing the file ...
. Browsing %windir%\assembly\ (for example, C:\WINDOWS\assembly) or %WINDIR%\Microsoft.NET\assembly, displays the assemblies contained in the cache along with their versions, culture, public key token, and processor architecture. Assemblies are installed by dragging and dropping and uninstalled by selecting and pressing the
delete key The delete key is a key on most computer keyboards which is typically used to delete either (in text mode) the character ahead of or beneath the cursor, or (in GUI mode) the currently-selected object. The key is sometimes referred to as the "for ...
or using the
context menu A context menu (also called contextual, shortcut, and pop up or pop-up menu) is a menu in a graphical user interface (GUI) that appears upon user interaction, such as a right-click mouse operation. A context menu offers a limited set of choice ...
. With the launch of the .NET Framework 4, the Assembly Cache Viewer shell extension is obsolete.


Example of use

A computer has two CLI 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 (FAT) is a file system developed for personal computers. Originally developed in 1977 for use on floppy disks, it was adapted for use on hard disks and other devices. It is often supported for compatibility reasons by c ...
file system In computing, file system or filesystem (often abbreviated to fs) is a method and data structure that the operating system uses to control how data is stored and retrieved. Without a file system, data placed in a storage medium would be one larg ...
. 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 CLI. The folders within %systemroot% named assembly and Microsoft.NET\assembly (for .NET 4.0) contain 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. Windows 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 a version of an assembly when referencing it, so the run-time can simply refer to the filename to use the correct one.


Pitfalls

The Global Assembly Cache mechanism helps to avoid older
DLL hell In computing, DLL Hell is a term for the complications that arise when one works with dynamic-link libraries (DLLs) used with Microsoft Windows operating systems, particularly legacy 16-bit editions, which all run in a single memory space. DLL Hel ...
, but it still has some drawbacks, such as: * By default, applications will only run with the version of the
.NET Framework The .NET Framework (pronounced as "''dot net"'') is a proprietary software framework developed by Microsoft that runs primarily on Microsoft Windows. It was the predominant implementation of the Common Language Infrastructure (CLI) until bein ...
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 In computer programming, conditional compilation is a compilation technique which results in an executable program that is able to be altered by changing specified parameters. This technique is commonly used when these alterations to the program a ...
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. 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 cannot be registered in the GAC. In cases where the code of the third-party assembly is not in the programmer's possession, transforming the assembly to be strongly named can in fact be impossible. * Browsing for files using standard Windows APIs doesn't allow selection of DLLs located under the "assembly" folder when Explorer is showing the user-friendly view of the GAC.


See also

* Download Cache *
.NET Framework The .NET Framework (pronounced as "''dot net"'') is a proprietary software framework developed by Microsoft that runs primarily on Microsoft Windows. It was the predominant implementation of the Common Language Infrastructure (CLI) until bein ...


References


External links


.NET Framework Developer's Guide

Global Assembly Cache Tool (gacutil.exe)

Demystifying the .NET Global Assembly Cache
{{Common Language Infrastructure .NET terminology Common Language Infrastructure Windows administration