WPF application crashes on .Net 3.0 platforms

0

I’m in the process of replacing the GUI of an existing C++ project to WPF. This made me learn some C# and have a first look at .Net. I chose compiling to target .Net 3.0 so that all machines from Vista SP2 up will be able to run my application. This makes the installation requirements unambiguous and shorten the installation time. I develop on a VS2012 on a Windows 8 machine (x64).

The code consists of Pure C++, C++/CLI glue and C#/XAML code for WPF. The application runs fine (Release configuration) on my development machine and on a Vista (x32) machine with .Net 4.5.1 installed.

It crashes on Windows 7 (x64/x32) machines and on Vista SP2 machines with .Net 3.0/3.5 I isolated the crash to the point where the pure C++ loads the C++/CLI glue DLL file.

From Dependency Walker (running Profile) on a Windows 7 machine:

LoadLibraryExW("C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorrc.dll", 0x00000000, LOAD_LIBRARY_AS_DATAFILE) called from "MSCORWKS.DLL" at address 0x690603E5. Mapped "MSCORRC.DLL" as a data file into memory at address 0x007B0001.   
LoadLibraryExW("C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorrc.dll", 0x00000000, LOAD_LIBRARY_AS_DATAFILE) returned 0x007B0001. 
Second chance exception 0xE0434F4D (Unknown) occurred in "KERNELBASE.DLL" at address 0x75B29617.

It seems that the application is loading a .Net 2.0 reference library although .Net 3.0 (and 3.5) is installed on the machine:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0]
"Version"="3.0.30729.4926"
"CBS"=dword:00000001
"Increment"="4926"
"Install"=dword:00000001
"SP"=dword:00000002

Here are my questions:
1. Is it possible to trap this exception so that the user gets a graceful exit?
2. Is it possible to determine from my application the .Net framework installed on the target machine (Besides reading the registry)?
3. Why does my application try to load a V2.0 file?
4. How can I verify that my application is indeed targeting V3.0?

Update:
Well, I've learnt quite a lot here, but my conclusions are not promising:
If you target your application to .NET 4.0 then your application might crash when running on a machine that lacks this framework.
The crash occurs on the first call from pure C++ to a C++/CLI function. There's no way to catch it as it occurs on the framework boundaries.
I've found a workaround to the crash: Assuming you have a pure C++ project called 'A' that consists of a A.CPP file that calls a function from a C++/CLI DLL called 'B'. Just add an empty file 'C.CPP' to project 'A' and mark this file to be compiled with /clr flag. This will make project 'A' a mixed-language project and instead of a crash you will get the following message box (which is acceptable):
enter image description here
Sad enough, if you develop using Visual Studio 2012 Express, your target is always .NET 4.x.
In other words, if you want your application to run on Windows 7 (Without additional packages) then you must develop using VS2008.

.net
wpf
c++-cli
asked on Stack Overflow Jan 8, 2014 by Shaul • edited Jan 14, 2014 by Shaul

1 Answer

1

It seems that the application is loading a .Net 2.0 reference library

This is entirely normal, the core libraries (like mscorlib) are still v2.0.50727 in .NET 3.0 and 3.5.

Second chance exception 0xE0434F4D (Unknown)

You cannot diagnose an unhandled .NET exception with Dependency Walker, it doesn't know anything about managed code. If you can't get a managed debugger to the machine then use DebugDiag.

And improve your program so these crashes don't fail the program without a diagnostic message. Write an event handler for the AppDomain.CurrentDomain.UnhandledException and display or log the value of e.UnhandledException.ToString(). You'll get the exception message and the holy stack trace that shows you how your program failed.

answered on Stack Overflow Jan 8, 2014 by Hans Passant

User contributions licensed under CC BY-SA 3.0