Wednesday, February 16, 2005

Uninstaller does not remove all installed assemblies from the GAC

Problem: Assemblies installed by your installer into the GAC, cannot be removed upon uninstallation. (Unable to uninstall assembly or application completely)
You installed assemblies into the GAC, and you weren't able to remove them using all three of the following methods
1. Using the .Net configuration manager
2. Trying to manually delete them form c:\WinNT\assembly3. using the gacutil /u or /uf option on the assembly
Trying any of the above methods, will lead to a message that says that the assembly is still being referenced by another application.
If you run gacutil /lr assembly, you will see that the application that is still referencing the assembly is the MSIInstaller.
I found that the problem was in a value in the registry.
Goto HKEY_CLASSES_ROOT\Installer\Assemblies\Global
the key (default) should not have a value. (so its value should read as (value not set))
if the value is either empty or any other value, then you will not be able to remove your assembly from the GAC.
Solution:
Goto HKEY_CLASSES_ROOT\Installer\Assemblies\Globalclick on the key (default), hit delete.
This should reset the value of (default) so that its value comes up as (value not set).
After this you should be able to uninstall your assembly from the GAC.
If you are creating an installer, then make the installer, delete this key from the registry. Then when the user uninstalls the application, it will remove all your assemblies from the GAC too.
I have no idea why this works. Cant even give you a reason as to why .NET framework needs to look at that key to decide if it can remove an assembly from the GAC. But apps like MSN IM 6.0 insert a value into the default key, and this can mess the uninstall procedure of your app.
The HKEY_CLASSES_ROOT\Installer\Assemblies\Global\ area is used to store information about shared assemblies deployed on the machine. But as far as I can see the (default) key should not be used.
A good thing to know