I have a DLL supplied by a 3rd party along with an accompanying .NET 2.0 assembly that wraps it. If I create a .NET 3.5 project with VS2008 I am able to call into the DLL via the wrapper assembly and it works OK. However, if I create an equivalent .NET 4.0 project with VS2010 then I get a R6030 - CRT not initialized
error in a message box at the time the DLL is loaded.
Is there something I can do to get this to work in a .NET 4.0 project? Could it be related to the CAS changes, or something else?
I'm carrying on with my work in VS2008 for now, but it would be good to understand what's happening...
That's not a .NET error, it is a MS C Runtime (CRT, MSCRT) error.
Your 3rd party dll is presumably using some MSCRT dll (there are lots of versions). At process start up of a native application the CRT is initialised (it contains the program entry point which then calls main
). There is also an entry point for new threads to ensure per-thread data is set up correctly.
If .NET 2 runtime1 by default uses the same MSCRT as the native code then it will be correctly initialised. .NET 4 presumably uses a newer version (new MSCRT versions tend to come with new versions of VS, as .NET does) then the older MSCRT is only being loaded as a dependency and not used for application startup.
Most of the time MSCT handles this correctly, but if the 3rd party dll is doing something "clever" it might be bypassing some initialisation, and this just happens to work is the same version of MSCRT is used by .NET. An example of such incorrect usage is to directly call CreateThread
rather than using the MSCRT _beginthread
wrapper.
To root cause this you will need sufficient understanding of the 3rd part dll and wrapper—more likely you need to supply a re-create to the third party for them to fix.
1 Remember V3.5 is just extra assemblies on top of the 2.0 CLI.