C# – How to remove a dll from the GAC when Gacutil.exe refuses service

cgacnet

I have an old version of the Enterprise Library in GAC. It resists any attempt on its life made with GACUTIL.EXE claiming the following:

Microsoft (R) .NET Global Assembly Cache Utility. Version 3.5.30729.1
Copyright (c) Microsoft Corporation. All rights reserved.

Assembly: Microsoft.Practices.EnterpriseLibrary.Common,
Version=4.1.0.0, Culture=neutral, PublicKeyToken=e44a2bc38ed2c13c, processorArchitecture=MSIL
Unable to uninstall: assembly is required by one or more applications
Pending references:
SCHEME: <WINDOWS_INSTALLER> ID: <MSI> DESCRIPTION : <Windows Installer>
Number of assemblies uninstalled = 0 Number of failures = 0

I found some explanation on the subject here, but I can’t find any relevant registry keys.

So I want the nuclear option. Whose got one?

Best Answer

Had the exact same problem with the OpenXml SDK Productivity Tool which only exists in version 2.5 but not in the latest 2.8.1.

After updating the SDK for my ASP.Net webpage in Visual Studio using Nuget Package Manager I had the problem that during the publish process the old "DocumentFormat.OpenXml V.2.5" dll was published and not the new one (which was referenced correctly in my Visual Studio project).

So I decided to uninstall the old SDK first by using the "Programs and Features" page and afterwards the "Uninstall"-Option of the MSI installer file.

Neither of it worked. Somehow the dll remains in the GAC and in the Registry. I tried to uninstall it using GACUTIL.exe, but I got the above Message:

    Unable to uninstall: assembly is required by one or more applications
Pending references:
SCHEME: <WINDOWS_INSTALLER> ID: <MSI> DESCRIPTION : <Windows Installer>

Then I deleted the registry key value for (ONLY THE VALUE, NOT THE KEY ITSELF)

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Assemblies\Global
DocumentFormat.OpenXml,version="2.5.5631.0",culture="neutral",publicKeyToken="31BF3856AD364E35". 

And that worked for me. Afterwards the correct dll is published! Hope it helps someone!