How does .NET / COM work with multiple versions registered through Regasm?

I have a .NET DLL (this happens to be written in C ++ / CLI). I want to open parts of it through COM. I do this and register it with "regasm my.dll / codebase". So far, so good. But then I change some things, and the build version number changes, and I move the dll to another folder. I will register it again and look at my COM object in the OLE / COM Viewer. I see something like this

  InprocServer32 [Codebase] = file: // c: //foo/bar/my.dll
 7.0.0.0 [Class] = My.Blah.Class
 7.0.0.0 [Assembly] = Sync, Version = 7.0.0.0, Culture = neutral, PublicKeyToken = 1dd19234234
 7.0.0.0 [RuntimeVersion] = v2.0.50727
 7.0.0.0 [CodeBase] = file: // c: /dooby/do/my.dll
 7.0.0.27397 [Class] = My.Blah.Class
 7.0.0.27397 [Assembly] = Sync, Version = 7.0.0.27397, Culture = neutral, PublicKeyToken = 1dd19234234
 7.0.0.27397 [RuntimeVersion] = v2.0.50727
 7.0.0.27397 [CodeBase] = file: // c: //foo/bar/my.dll

Questions about multiple versions:

  • Therefore, I think the last COM object that was registered wins. It doesn’t matter if my old 7.0.0.0 COM object was registered with me, 7.0.0.27397 is the one that will be created when I create an instance of my COM object, because I registered it last. It is right?

  • Unfortunately, I did not support the 7.0.0.0 object. Is there any way to get rid of it? Is there a way to delete all versions of a COM object, except for entering the registry and manually hitting it?

  • Just out of curiosity, if I specifically wanted to instantiate a specific version of my COM object, is there a way to do this? (I use C ++ if you want to give a code example).

  • Is there a way that I can just tell regasm not to store the version number, because it just outshines things, and I don’t see what an advantage. If my COM object went through a major API change, I would just change the GUID and progid, right? What if I do not want to register several versions (I do not do this).

+6
com versions regasm
source share
2 answers

I always installed my COM-visible assemblies with static AssemblyVersion for this very reason. If you want to have binaries with version tags, use AssemblyFileVersion instead.

  • Last registered object to win: yep
  • Not really. You can put stuff into your ComRegisterFunction / ComUnregisterFunction assembly, attributed methods to automate cleaning, but if you leave the old version unchecked, this will be the only way.
  • You would do this with a different GUID GUID and / or ProgID (e.g. MyCoClass.1, .2, etc.). CoCreateInstance does not know anything about version values ​​- they are used by the CLR activator to ensure loading of the right assembly.
  • Not. It’s best not to change your version of the assembly (see above).
+5
source share

Components with the same CLSID must be compatible, especially if you only changed the assembly number between assemblies. Here is the only relevant thing I found to confirm this with a quick googling search.

To answer your questions directly:

0
source share

All Articles