Assemblies in GAC and their dependencies

Global Assembly Cache (GAC) is a machine wide central repository of shared components. For that matter maybe GAC should really be called Global Assembly Store. But for historically reason GAC is called Global Assembly Cache, and will be kept as it is in the foreseeable future.

 

Assemblies in GAC must be strongly named. Strongly name signing serves as two purposes:

  1. Integrity. CLR will be able to tell if the assembly has been tampered or not with strong name signature verification.
  1. Unique identity. Theoretically, two assemblies with the same strong name should be considered as identical.

 

An installer uses fusion GAC APIs to install assemblies to GAC, as well as uninstall them from GAC. The recommended way to install assemblies to GAC is using MSI. In the cases MSI is not an option (like the assembly is generated on the fly), you can write a custom installer using fusion's GAC APIs.

 

Currently GAC APIs installs assemblies one at a time. There is no restriction that the assembly and its dependencies must all be in GAC, nor is there any guarantee that all the assembly's dependencies will be in GAC. It is the application developer or component developer's responsibility to make sure all the dependencies are installed, if this is required.

 

In the case that an assembly is in GAC, but some of its dependencies are not in GAC, it is very likely to get an assembly loading exception for applications using this assembly. To avoid this, you can re-write part of the assembly to use dynamic activation (like Activator.CreateInstance) for types in dependencies not installed in GAC, and handle the missing dependencies exception gracefully inside your assembly.