.NET - The Global Assembly Cache and Reference Assemblies

A quick review

The .NET GAC is a repository for system-wide shared assemblies.

It is used primarily by Microsoft as the public location for the .NET Framework.

The principal advantage of deploying to the GAC, is that you will have a single copy of the assembly, and more importantly a single point of update.

Reference Assemblies

In Visual Studio, if you add a reference to a Microsoft assembly (E.g. System.Data.dll), the compiler will resolve the reference to a directory under Program Files \ Reference Assemblies. It does not point to the GAC. Not yet. Not until runtime.


You can view the full path to System.Data.dll in the Object Browser:
(Right click on the assembly reference and select View in Object Browser). Properties ... Path will also work fine.
[images/view-in-object-browser.gif]
Assembly System.Data
    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.dll

Note that the reference does not point to the GAC, even though the assembly will be loaded from the GAC at runtime.


The Reference Assembly constitutes the published API for a specific version of the framework. If you link to v4.6.1, for example, then you won't see methods that were added in v4.6.2.
It allows you to target a version the Framework, as it appeared when it was released. Unlike the GAC, you won't see patch updates. Using Reference Assemblies prevents you from unintentionally using methods that were not present in the initial public release. You will still get the runtime behaviour of the assembly that is installed in the GAC (patches included), but the metadata in the Reference Assembly will prevent you from coding against a method that was added (or removed) in a subsequent build.


Checking the load path

You can view the runtime load path in the VS Output Window, or under Debug ... Windows ... Modules.


For a 32-bit process, you will see:

'Test.exe' (CLR v4.0.30319: Test.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'.

For a 64-bit process, you will see:

'Test.exe' (CLR v4.0.30319: Test.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'.


Ads by Google

Ask a question, send a comment, or report a problem - click here to contact me.

© Richard McGrath