BUG: Mscorwks.dll does not initialize (327434)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Professional Edition

This article was previously published under Q327434

SYMPTOMS

When you run an unmanaged application that links to a managed DLL, you receive the following error message in a Microsoft .NET Framework Initialization Error dialog box:
C:\Windows\Microsoft.Net\Framework\v1.0.3705\mscorwks.dll cannot be loaded.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Use the following code to create a file named 1.cpp:
    //1.cpp (unmanaged)
    __declspec(dllimport) int Func2();
    
    int g_1 = 0;
    
    __declspec(dllexport) int Func1()
    {
    return (g_1 + Func2());
    }
    					
  2. Use the following code to create a file named 2.cpp:
    // 2.cpp (managed)
    int g_2 = 0;
    
    __declspec(dllexport) int Func2()
    {
    return (g_2 + 2);
    }
    					
  3. Use the following code to create a file named Main.cpp:
    //main.cpp
    __declspec(dllimport) int Func1();
    __declspec(dllimport) int Func2();
    
    int main()
    {
    return ( Func1() + Func2() );
    }
    					
  4. Compile 2.cpp to a managed DLL:
    cl /clr /LD 2.cpp
    					
  5. Compile 1.cpp to an unmanaged DLL with the /MD command as follows (this links with the multi-threaded DLL version of the C runtime):
    cl /MD /LD 1.cpp /link 2.lib
    					
  6. Compile Main.cpp to an unmanaged executable (.exe) file:
    cl main.cpp /link 1.lib 2.lib
    					
  7. Run Main.exe. When Main.exe is run, the operating system loads 1.dll. 1.dll has a dependency on 2.dll, so 2.dll is loaded. 2.dll starts the Microsoft .NET runtime, which causes malloc to be called. The call to malloc is not successful because the C runtime has not been initialized yet. The C runtime has not been initialized because 1.dll has a reference to it (which prevents 2.dll from initializing it.)

Modification Type:MinorLast Reviewed:8/25/2005
Keywords:kbvs2002sp1sweep kbbug KB327434