.netcomtypeliboleview

Unable to remove COM [PrimaryInteropAssemblyName] typelib value using REGASM /u


I was hoping someone can point me in the right direction. I listed the problem in a few steps to hopefully clarify the issue.

  1. I register a C++ DLL into COM using regsvr32.
  2. I then use tlbimp with the /primary attribute on the C++ DLL to make an assembly file that can be used by C#.
  3. I then register the newly generated assembly into the GAC.
  4. I call regasm on the generated assembly so that the C++ type library contains a reference to the GACed assembly.

The problem is that when I use regasm /u, it says it was "unregistered successfully". But, when I check the typelib in COM using OLEVIEW it still shows the PrimaryInterop reference to the GACed assembly.

I have tried using regasm /u /tlb aswell, but I get a warning saying this:

RegAsm : warning RA0000 : Type library not un-registered since the assembly was
imported from COM

enter image description here

Thanks for any assistance as this is driving me crazy ;)


Solution

  • Step 4 is wrong, the COM server was already registered in step 1. You only use Regasm.exe when you create your own COM server ([ComVisible] attribute), not when you merely use one. Using /primary in step 2 is iffy as well, you only need a PIA when you expose the COM types that you imported in your own public interface. Best avoided. Fix the damage you might have done by repeating step 1.

    The interop assembly that's generated by tlbimp.exe is just a little helper assembly that only contains declarations, auto-generated from the type library. Helps the CLR to generate thunks for the COM interface methods without having to parse a type library. Be sure to use the Embed Interop Types feature available in VS2010 if you have that edition.