For those of you out there using COM interop with your current applications to either call a .NET component from unmanaged code through COM Callable Wrappers (CCW) or call an unmanaged component from .NET code through Runtime Callable Wrappers (RCW) and are running side-by-side versions of the .NET  Framework (v1.1.4322 and v2.0.50727), listen up.

There seems to be a problem with COM interop (in particular CCW) when having side-by-side versions of .NET Framework installed on your machine (thanks to Eran Sandler for pointing this out).  I was informed today at work that an unmanaged (VB6) application that calls a .NET Windows Form (created in v1.1) was getting an exception when it tried to load information from the app.config file.  It appears that the Windows Form was being loaded and executed using the 2.0 version rather than the 1.1 version of the framework.  It was puzzling because a .NET application will use the version of the assembly it was built on.  If there weren’t the case, we would still have DLL Hell with our applications. 

In my laptop, I have both .NET 2.0 and 1.1 installed.  If you look at the typelib entry for System.Object under HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{81C5FE01-027C-3E1C-98D5-DA9C9862AA21}, you will notice the InprocServer32 key has two subkeys named 1.0.5000.0 and 2.0.0.0 respectively.  Under these keys, you’ll notice the RuntimeVersion key that specifies the version of the runtime in which the CCW was built under.  For some reason, .NET will not load the types that have a value of v1.1.4322 (.NET v1.1).  Why?  I don’t know quite yet, but I’m looking into it….more to come on this…

Don’t worry, there’s a solution!  To fix all of this mess, you will need to force the unmanaged application that hosts the 1.1 version of your CCW to load under .NET 1.1 by using the requiredRuntime element in your app.config file for your unmanaged application.  Although, this might seem a bit cumbersome, it’s the only way to get things working under the right runtime version as the AppDomain loads.

Hope this helps!