Microsoft KB Archive/327125

= BUG: .NET Framework Initialization Error Occurs with Certain DLL Dependencies =

PSS ID Number: 327125

Article Last Modified on 10/19/2002

-

The information in this article applies to:


 * Microsoft Visual C++ .NET (2002)
 * Microsoft Visual C++, 32-bit Editions 6.0
 * Microsoft Common Language Runtime (included with the .NET Framework) 1.0
 * Microsoft .NET Framework 1.0

-



This article was previously published under Q327125



SYMPTOMS
When you start a managed application, you may receive the following error message:

.NET Framework Initialization Error

c:\YourFrameworkPathHere\mscorwks.dll could not be loaded

After you dismiss this error message, you receive the following error message:

The application failed to initialize properly (0xc0000142). Click on OK to terminate the application.



CAUSE
This error occurs because the application startup calls the C-Runtime before it is completely initialized.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
There are two known scenarios that cause this problem.

Scenario One:
A nondebug EXE is mixed with a managed debug DLL. This scenario only occurs on a computer that is running Windows 2000 or Windows XP.   To build the managed debug DLL, copy the following code to TestDLL.cpp: __declspec(dllexport) void test {}   To build this DLL, use the following command line: cl /LD /MDd /clr testDLL.cpp   To build the nondebug EXE, copy the following code to Test.cpp: extern void test;

int main { test;

}   To build this EXE, use the following command line: cl /MD test.cpp testDLL.lib  Run test.exe, and notice that you receive the error message that is described in the &quot;Symptoms&quot; section.</ol>

Scenario Two:
Use an unmanaged DLL that is built with the Visual C++ version 6.0 compiler (Cl.exe), which depends on a managed DLL that is built with Visual C++ .NET. You can reproduce the error with the following sample code and build options.

NOTE: These steps require that you have both Visual C++ 6.0 and Visual C++ .NET available.

Build the Managed DLL

<ol>  Copy the following sample code to a file that is named Managed.cpp: int g_2 = 0;

__declspec(dllexport) int Func2 {   return (g_2 + 2);

} </li> Build this code on the Visual C++ .NET system. Run the Vcvars32.bat file that is located in the \Microsoft Visual Studio .NET\VC7\bin directory to configure a CMD prompt session for command line builds.</li>  To build Managed.dll, use the following command line: cl /clr /LD Managed.cpp </li></ol>

Build the Unmanaged DLL <ol>  Copy the following sample code to a file that is named UnManaged.cpp: __declspec(dllimport) int Func2;

int g_1 = 0;

__declspec(dllexport) int Func1 {   return (g_1 + Func2);

} </li> Build this code with Visual C++ 6.0. Run the Vcvars32.bat file that is located in the \Microsoft Visual Studio\vc98\bin directory to configure a CMD prompt session for command line builds.

NOTE: This must be a separate CMD session from the first build so that the PATH and the other environment variables that are created by Vcvars32.bat do not conflict.</li>  To build UnManaged.dll, use the following command line: cl /MD /LD UnManaged.cpp /link Managed.lib </li></ol>

Build the Main Application <ol>  Copy the following sample code to a file that is named Main.cpp: __declspec(dllimport) int Func1; __declspec(dllimport) int Func2;

int main {   return ( Func1 + Func2 );

} </li>  You can build this code with either the managed code process or the unmanaged code process (the compiler version is not critical). To build this code, use the following command line: cl main.cpp /link Managed.lib UnManaged.lib </li> Run Main.exe, and notice that you receive the error message that is described in the &quot;Symptoms&quot; section.</li></ol>

Keywords: kbbug kbCRT kbIJW kbManaged KB327125

Technology: kbAudDeveloper kbComLangRunT kbComLangRunT100 kbNETFrame kbNETFrame100 kbVC32bitSearch kbVC600 kbVCNET kbVCsearch

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© 2003 Microsoft Corporation. All rights reserved.