RegAsm - completely unregistering library (including typelib) for 32b and 64b COM

447 Views Asked by At

I have a .NET assembly that should be registered both for 32b and 64b COM interop. Our installation script successfully registers this and everything works as expected.

We want our UNinstallation script to remove fully the registration that was done in the install script, but I'm unable to do this. Some registry entries always remain.

I set up a reproducible test case:

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\regasm.exe "C:\Path\To\MyLibrary.dll" /codebase /tlb
C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\regasm.exe "C:\Path\To\MyLibrary.dll" /codebase /tlb

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\regasm.exe "C:\Path\To\MyLibrary.dll" /u /tlb
C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\regasm.exe "C:\Path\To\MyLibrary.dll" /u /tlb

As you can see, this registers the library for both 32b and 64b (Framework and Framework64 directories used) and exports and registers the type libraries (/tlb parameter).

The same is done to unregister the libraries (.dll and .tlb files).

The full output is

C:\>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\regasm.exe "C:\Path\To\MyLibrary.dll" /codebase /tlb
Microsoft .NET Framework Assembly Registration Utility version 4.8.4084.0
for Microsoft .NET Framework version 4.8.4084.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Types registered successfully
Assembly exported to 'C:\Path\To\MyLibrary.tlb', and the type library was registered successfully

C:\>C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\regasm.exe "C:\Path\To\MyLibrary.dll" 
/codebase /tlb
Microsoft .NET Framework Assembly Registration Utility version 4.8.4084.0
for Microsoft .NET Framework version 4.8.4084.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Types registered successfully
Assembly exported to 'C:\Path\To\MyLibrary.tlb', and the type library was registered successfully

C:\>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\regasm.exe "C:\Path\To\MyLibrary.dll" /u /tlb
Microsoft .NET Framework Assembly Registration Utility version 4.8.4084.0
for Microsoft .NET Framework version 4.8.4084.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Types un-registered successfully
Type library 'C:\Path\To\MyLibrary.tlb' un-registered successfully

C:\>C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\regasm.exe "C:\Path\To\MyLibrary.dll" 
/u /tlb
Microsoft .NET Framework Assembly Registration Utility version 4.8.4084.0
for Microsoft .NET Framework version 4.8.4084.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Types un-registered successfully
Type library 'C:\Path\To\MyLibrary.tlb' un-registered successfully
PS C:\> 

Note that in both cases the output mentions that the type libraries were unregistered succesfully.

However, if I look in my registry, I see see remnants of my type library at HKEY_CLASSES_ROOT\TypeLib\{E9E332B2-... snip ... -E6B627A4642E}\1.0\0\win32

If I comment out either the 32b xor the 64b registration/unregistration statements, then the registry is back in a pristine state without remnants. Only when I register/unregister both 32b and 64b do I have remnants, despite the output claiming to have unregistered everything.

I suspect this is a regasm bug, but I'll await the community feedback.

1

There are 1 best solutions below

1
On

I'm very late to the party but if anyone else is experiencing the same issue I hope this answer helps.

In order to completely remove the library and it's typelib too you need to use:

regasm "Path to library" /tlb /unregister