I have a managed C ++ dll with several managed classes, which in turn call native C ++ code in a library that I statically linked to dll. However, if I try to run RegAsm.exe in the dll, the tool correctly says "there are no types that we registered", but then freezes . I am very sure that this is a bootloader lock problem , and my dll freezes when RegAsm tries to load it. I am using Visual Studio 2008 Express Edition.
Which makes me think that everything works fine when placing your own code in the dll, but not when statically linking it from the library. I know this post is similar to this question , but I do not have DllMain in my dll, there is no risk for me MSIL code from DllMain. In addition, on the recommendation, setting / clr for individual files did not help.
Compiling the dll with / NOENTRY fixes the lock problem, but causes the application to crash with a Type initializer for <Module> threw exception and is apparently only recommended with .NET 2003.
I suspect that initializing static members may be a possible culprit, but why would this be compiled for MSIL in my static lib outside of me.
Just to clarify: although I do not need to run RegAsm.exe in the dll, I use it as a check for the bootloader lock problem. I actually consume a dll in a C # assembly that implements several classes visible in COM, so I need to record COM on this. At the end of the C # IDE crashes during registration for COM interaction, reports βR6033 C ++ runtime error: try to use the MSIL code from this assembly while initializing your own code. This indicates an error in your application. Most likely, this is the result calling an MSIL-compiled (/ clr) function from a native constructor or from DllMain.
I solved the problem, but little is unclear, and I'm curious:
I noticed that two static variables were added to the header file in a statically linked library at the time when everything stopped working, it looked like this:
// The whole header is forced to compile as native
Moving the initialization to the .cpp file (and changing the static to extern ) removes the bootloader lock. Can anyone indicate why the initializer will be compiled into MSIL?
Before the fix, if I only # included the header file from the managed dll, everything worked fine. But if I included the AND header, also associated with lib, it did not work. Since lib also uses a header inside itself, did I end up with two instances of a static variable? In any case, why complain about running MSIL code?
Despite the fact that now everything works, any understanding will be welcome.