I have a need to call some C# code from a native C++ class library. The class library uses MFC in a shared dll. Thanks to this Stackoverflow post, I recently learned that it is possible to compile only selected files with the /clr option. That's great, it seemed like a clean approach, both from a design perspective as well as from a practical point of view, since the minimal rebuild and precompiled headers functionality is incompatible with /clr.
So I went ahead and added a new C++ class, set the /clr option and wrote some code to call into a .Net dll. So far so good, everyting compiles and even Intellisense works occassionaly. But at runtime I run into problems. When I use the class library from a unit test project, I get an assertion.
I get no stack trace, but the assertion is triggered in the mfc dll (mfc120d.dll in my case) in dllmodul.cpp in function InternalDllMain at this line
VERIFY(AfxInitExtensionModule(controlDLL, hInstance));
This happens on startup, before any testcases are run and before any calls to .Net code. Everything works fine when I link the library from an MFC application.
What's going on and how do I fix it?