Search code examples
c#.netcom.net-assembly

Prevent .NET from reusing assembly during COM call


I'm creating a .NET assembly with a COM interface. Ideally I'd like to have registry keys separated from the assembly so performing a release only needs to drop a .dll on a shared drive (rather then needing to push out an MSI each time)

I created different classes that inherited from the main class to get different GUIDs for each environment.

However when I test this the first version loaded (eg. development) ends up servicing calls for the other environments (eg. test) later on. This wouldn't normally be a problem but when used this component is called from an all day running GUI executable. Conceivably people could be running different environments throughout the day.

Each interface has an independent codebase set in the registry (no GAC) and the process monitor shows that both assemblies are loaded yet only the first is used. I presume that's because .NET is seeing the same class/assembly name and reusing the first one loaded.

How I can isolate the assemblies in this situation?


Solution

  • You can strong name the assemblies ("signing" tab in project properties in Visual Studio, not to be confused with Authenticode signing) and change either the version number, public key or both for the different versions/environments. This way the CLR assembly loader will consider them different and will not bind to the one that's already been loaded in the given context.