GAC Assembly Trace Reference

When you install an assembly to GAC, you have the option to specify an Assembly Trace Reference.

And we strongly recommend that you specify a trace reference, for the reason I will discuss below. 

The idea behind trace reference is really simple. When multiple applications install the same assembly, and one application is uninstalled (thus uninstall the assembly it carries), other applications won’t be broken.

But trace reference is not a simple numberic COM like reference count. Numberic reference count does not protect against accidental assembly uninstall, since there is no way to connect the applications with the referece count. We want to provide a way for applications to say that this application requires that assembly.

A trace reference consists of three parts: A scheme(choose from a pre-defined set), a string for application id, and a string for application specific description. An application can choose a scheme, a unique identity, and informational description for the application or the assembly.

There are three pre-defined schemes: OPAQUE, UNINSTALL_KEY and FILEPATH.

If the scheme is OPAQUE, application defines the meaning of id and description. We simply record them as the trace reference.

For UNINSTALL_KEY scheme, we intepret the id as the application’s uninstall id (what you see when you bring up Add/Remove applications). If we can’t find the uninstall id, we assume that the application is uninstalled, and we will remove the trace reference.

When an application uses FILEPATH, it specifies the id to be a filepath. If we find the file does not exist anymore, we will remove the trace reference.

When an assembly is installed with a trace reference, you have to uninstall it with the exact same trace reference. If we find that there are more trace references, we will simply remove the trace reference, without remove the actual bits from GAC. When we find there are no more trace reference left, we will remove the bits from GAC. This is why we recommend installing assembly with a trace reference. Otherwise the assembly may be accidentally removed from GAC, when another application is removing its trace reference.

Assemblies installed with Microsoft Installer (MSI) will automatically carry a trace reference. And that trace reference can only be removed by uninstall the application through MSI.

Gacutil.exe is able to install assemblies with trace references, uninstall assemblies with trace references, as well as listing trace references of a particular assembly. See gacutil’s help for more information, and look for “/r” option.

In practice, we found the OPAQUE scheme is used most. People do want to manage the trace reference themselves. 

Comments (4)

  1. GAC Assembly Trace Reference

  2. The new support for solution deployment in WSS 3.0 is great, HOWEVER if you are deploying shared assemblies

  3. Sono capitato un po' per caso a leggere questo post su Bamboo Nations (che, devo dire, sta scalando