Search code examples
c#comregasm

How do I unregister/remove all COM entries created in registry


How do I remove all COM entries registered in the registry for a ProgID("Log.Main").

I have a COM component which is registered using regasm and now I could see a multiple class Ids for this COM Component(using oleview.exe) under CLSIDs in registry("Log.Main").

I want remove all entries related to this COM component with ProgID 'Log.Main' from registry using C# or is there any tools available other that registry cleaners.


Solution

  • This is not generally possible unless you still have the original component. The ProgId only gives you the entry in the Classes registry key, the CLSID {guid}. You will not be able to find the entries in the TypeLib and Interface registry keys because you do not know their {guid}s.

    To avoid registry pollution, it is pretty important to unregister the component first before you rebuild it. That's done automatically by MSBuild when you use the "Register for COM interop" option, available in a .NET project on the Project + Build tab property page. With the quirk that you need to run VS elevated so MSBuild can monkey with the register, right-click the shortcut and choose Run as Administrator.

    If that is unpractical for some reason then you can find some relief by using the [Guid] attribute explicitly so the type library, interface and class guids are always the same. It is however very, very important to remove them again when you are done debugging and testing the component or you risk very serious DLL Hell when you make changes. Strongly favor MSBuild doing this automatically for you.