From: Øystein Skotheim on 30 Jul 2008 03:55 Hello. I have problems with an applications consisting of mixed native and managed code writted in C++/CLI in Visual Studio 2005. The application runs fine in "Debug mode", however when I compile the application in "Release" mode I run into the following exception: Exception: The type initializer for '<Module>' threw an exception. Inner exception: The C++ module failed to load during native initialization. The exception is thrown when the following statement is executed: MeasureDialog = gcnew GcpsDialog(); This dialog box contains references to another DLL: GcpsDotNetApi.dll, which is a managed wrapper around a native class. I can also see the following in the output window of Visual Studio 2008: '3DWorkbench.exe' (Managed): Loaded 'c:\svn\auto3d\3dworkbench\release\GcpsDotNetApi.dll', Symbols loaded. First-chance exception at 0x7c96cc82 in 3DWorkbench.exe: 0xC0000005: Access violation reading location 0x8de460e8. First-chance exception at 0x78138be3 in 3DWorkbench.exe: 0xC0000005: Access violation writing location 0x8de460e9. A first chance exception of type 'System.AccessViolationException' occurred in GcpsDotNetApi.dll A first chance exception of type '<CrtImplementationDetails>.ModuleLoadException' occurred in msvcm80.dll First-chance exception at 0x7c812a5b in 3DWorkbench.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.. First-chance exception at 0x7c812a5b in 3DWorkbench.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.. First-chance exception at 0x7c812a5b in 3DWorkbench.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.. A first chance exception of type 'System.TypeInitializationException' occurred in 3DWorkbench.exe What can I do to debug this problem further? How can I know what causes the apparent access violation in the GcpsDotNetApi.dll? I have tried to enable "debug information" when compiling as release mode, but this does not seem to give me any more information. (As I said, the problem does not appear when the application is compiled in debug mode.) Perhaps I should say that I first ran into another problem with my application in debug mode, namely a crash during startup telling "Assertion Failed! Expression: _CrtIsValidHeapPointer(pUserData)." It seems like this was caused by some native, global, static variables (e.g. STL lists) present in "GcpsDotNetApi.dll". After searching on the net for a while, I found a workaround telling me to force the symbol define "__DllMainCRTStartup(a)12" to enable running of some CRT initialization code. This made the error go away. I do not know if the problem that I experience now might be related to the same issue. Any help further is deeply appreciated :-) --- �ystein Skotheim Scientist, Optical Measurement Systems and Data Analysis SINTEF ICT [http://www.sintef.com/omd]
From: Giovanni Dicanio on 30 Jul 2008 05:27 "�ystein Skotheim" <oystein(a)dontspam.me> ha scritto nel messaggio news:g6p6ol$74s$1(a)kuling.itea.ntnu.no... > Hello. I have problems with an applications consisting of mixed native and > managed code writted in C++/CLI in Visual Studio 2005. > > The application runs fine in "Debug mode", however when I compile the > application in "Release" mode I run into the following exception: When you compile in release mode, are you sure that all the DLLs (I assume these are C++ or C++/CLI DLLs) you link with are built in release mode, and that you use the same version of the CRT (e.g. multithreaded DLL)? Giovanni
From: Øystein Skotheim on 31 Jul 2008 07:33 Giovanni Dicanio wrote: >> Hello. I have problems with an applications consisting of mixed native and >> managed code writted in C++/CLI in Visual Studio 2005. >> >> The application runs fine in "Debug mode", however when I compile the >> application in "Release" mode I run into the following exception: > > When you compile in release mode, are you sure that all the DLLs (I assume > these are C++ or C++/CLI DLLs) you link with are built in release mode, and > that you use the same version of the CRT (e.g. multithreaded DLL)? Hello. All the modules that are linked with the application are built in release mode. This is a list of all the units that are linked together, including the settings for MFC, CLR and standard library. 3DWorkBench.exe (C++/CLI) MFC in shared DLL CLR=Yes CRT=MT DLL AcqusitionLib.lib (C++) Standard Windows lib. CLR=No CRT=MT DLL GCPS.lib (C++) MFC in shared DLL CLR=No CRT=MT DLL GcpsConfigLib (C++/CLI) Standard Windows lib. CLR=Yes CRT=MT DLL GcpsDotNetApi.dll (C++/CLI) MFC in shared DLL CLR=Yes CRT=MT DLL LibHvUtil.lib (C++) Standard Windows lib. CLR=No CRT=MT DLL MSDN.Configuration.dll (VB) Visual Basic .NET class library ScalablePictureBox.dll (C#) Visual C# .NET class library Dependency walker says that GcpsDotNetApi.dll is dependent on the following libraries: c:\windows\winsxs\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700\MSVCR80.DLL c:\windows\winsxs\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700\MSVCP80.DLL c:\windows\winsxs\x86_microsoft.vc80.mfc_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_3bf8fa05\MFC80.DLL c:\windows\winsxs\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700\MSVCM80.DLL c:\windows\system32\KERNEL32.DLL c:\windows\system32\USER32.DLL c:\windows\system32\OLEAUT32.DLL c:\windows\system32\GDI32.DLL c:\windows\system32\MSCOREE.DLL Any other ideas for what could be causing my error? It would be very helpful if there is anything that I can do to debug what is causing the "access violation during native initialization" of the GcpsDotNetApi.dll file. -- �ystein Skotheim Scientist, Optical Measurement Systems and Data Analysis SINTEF ICT, Trondheim, Norway
From: Ben Voigt [C++ MVP] on 31 Jul 2008 09:46 �ystein Skotheim wrote: > Giovanni Dicanio wrote: > >>> Hello. I have problems with an applications consisting of mixed >>> native and managed code writted in C++/CLI in Visual Studio 2005. >>> >>> The application runs fine in "Debug mode", however when I compile >>> the application in "Release" mode I run into the following >>> exception: >> >> When you compile in release mode, are you sure that all the DLLs (I >> assume these are C++ or C++/CLI DLLs) you link with are built in >> release mode, and that you use the same version of the CRT (e.g. >> multithreaded DLL)? > > Hello. All the modules that are linked with the application are built > in release mode. > > This is a list of all the units that are linked together, including > the settings for MFC, CLR and standard library. > > 3DWorkBench.exe (C++/CLI) MFC in shared DLL CLR=Yes CRT=MT DLL > AcqusitionLib.lib (C++) Standard Windows lib. CLR=No CRT=MT DLL > GCPS.lib (C++) MFC in shared DLL CLR=No CRT=MT DLL > GcpsConfigLib (C++/CLI) Standard Windows lib. CLR=Yes CRT=MT DLL > GcpsDotNetApi.dll (C++/CLI) MFC in shared DLL CLR=Yes CRT=MT DLL > LibHvUtil.lib (C++) Standard Windows lib. CLR=No CRT=MT DLL > MSDN.Configuration.dll (VB) Visual Basic .NET class library > ScalablePictureBox.dll (C#) Visual C# .NET class library > > Dependency walker says that GcpsDotNetApi.dll is dependent on the > following libraries: > > c:\windows\winsxs\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700\MSVCR80.DLL > c:\windows\winsxs\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700\MSVCP80.DLL > c:\windows\winsxs\x86_microsoft.vc80.mfc_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_3bf8fa05\MFC80.DLL > c:\windows\winsxs\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700\MSVCM80.DLL > c:\windows\system32\KERNEL32.DLL > c:\windows\system32\USER32.DLL > c:\windows\system32\OLEAUT32.DLL > c:\windows\system32\GDI32.DLL > c:\windows\system32\MSCOREE.DLL > > Any other ideas for what could be causing my error? It would be very > helpful if there is anything that I can do to debug what is causing > the "access violation during native initialization" of the > GcpsDotNetApi.dll file. Does the problem occur when a debugger is attached? The information you gave is from the point that the .NET framework catches the exception and pretty low quality. With a debugger attached, you'll trap the first-chance exception, at the point where the AV actually occurs.
From: Øystein Skotheim on 31 Jul 2008 10:36
Ben Voigt [C++ MVP] wrote: >>>> Hello. I have problems with an applications consisting of mixed >>>> native and managed code writted in C++/CLI in Visual Studio 2005. >>>> >>>> The application runs fine in "Debug mode", however when I compile >>>> the application in "Release" mode I run into the following >>>> exception: >>>> [...] > Does the problem occur when a debugger is attached? The information you > gave is from the point that the .NET framework catches the exception and > pretty low quality. With a debugger attached, you'll trap the first-chance > exception, at the point where the AV actually occurs. I run the program from within Visual Studio 2008 by clicking on "Start debug". Is this what you mean? Then I can step through the code. When I press F11 (Step Into) on the following code line, the exception saying access violation appears immediately in the output window of Visual Studio: MeasureDialog = gcnew GcpsDialog(); even if I set a breakpoint on the first line of the constructor of GcpsDialog. (A strange thing is that GcpsDialog is actually a part of the main application and not a part of GcpsDotNetApi.dll - but the dialog contains member variables that references into the DLL file - so I guess this is the line of code that triggers loading of GcpsDotNetApi.dll) These are the messages that appear when I press F11 on the above line of code: '3DWorkbench.exe' (Managed): Loaded 'c:\SVN2\Auto3D\3DWorkBench\release\GcpsDotNetApi.dll', Symbols loaded. First-chance exception at 0x7c96cc82 in 3DWorkbench.exe: 0xC0000005: Access violation reading location 0xc5fc4307. First-chance exception at 0x78138be3 in 3DWorkbench.exe: 0xC0000005: Access violation writing location 0xc5fc4308. A first chance exception of type 'System.AccessViolationException' occurred in GcpsDotNetApi.dll A first chance exception of type '<CrtImplementationDetails>.ModuleLoadException' occurred in msvcm80.dll First-chance exception at 0x7c812a5b in 3DWorkbench.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.. First-chance exception at 0x7c812a5b in 3DWorkbench.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.. First-chance exception at 0x7c812a5b in 3DWorkbench.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.. A first chance exception of type 'System.TypeInitializationException' occurred in 3DWorkbench.exe Regards, -- �ystein Skotheim Scientist, Optical Measurement Systems and Data Analysis SINTEF ICT, Trondheim, Norway |