Search notes:

.NET: Global Assembly Cache

A computer («machine») where the Common Language Runtime is installed also has a Global Assembly Cache.
The Global Assembly Cache is a machine wide location that stores assemblies that are intended to be shared among applications on that machine.
However, to make assemblies referrable to COM-interop or unmanaged code, they don't need to be installed in the GAC.
Assemblies in the GAC must have a strong name.
Starting with the *.NET Framework 4*, the default location for the Global Assembly Cache is %windir%\Microsoft.NET\assembly. In earlier versions, the default location was %windir%\assembly.
An assembly's filename, without its extension .dll or .exe, that is stored in the GAC must correspond to the name of assembly itself.

Viewing the content of the GAC

The content of the GAC can be viewed with gacutil -l:
PS C:\Users\Rene> gacutil -l
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.

The Global Assembly Cache contains the following assemblies:
  Microsoft.Ink, Version=6.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=AMD64
  Microsoft.Interop.Security.AzRoles, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=AMD64
  srmlib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=AMD64
  …
  XsdBuildTask, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
  XsdBuildTask.resources, Version=4.0.0.0, Culture=de, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL

Number of items = 979

Installing and removing assemblies into/from the GAC

An assembly is installed in the GAC either by
Install an assembly
P:\ath\to\xyz> gacutil -i TQ84.Foo.dll
Remove the assembly
P:\ath\to\xyz> gacutil -u TQ84.Foo
These commands must be executed with administrator privileges.

Loading assemblies from the GAC

The static method LoadWithPartialName() (class System.Reflection.Assembly) loads an assembly, using a partial name, from the GAC.

Testing if an assembly is loaded into the GAC

With Powershell, it is possible to test whether a specific assembly is loaded into the GAC like so:
# add-type  -path $env:oracle_home\ODP.NET\managed\common\Oracle.ManagedDataAccess.dll

foreach ($assembly in ([AppDomain]::CurrentDomain.GetAssemblies()) ) {

   if (  [System.Runtime.InteropServices.RuntimeEnvironment]::FromGlobalAccessCache($assembly) ) {
      write-host "$assembly was found in GAC"
   }
   else {
      write-host "$assembly was not found in GAC"
   }
}

See also

OraProvCfg.exe (along with configure.bat?) allows to put ODP.NET drivers into the GAC.
PowerShell modules that export assemblies into the GAC require a module manifest.

Index