I have a WPF program that runs fine on the development PC and on the client PC 1. But on client PC 2, it crashes immediately on startup with the Send Report to Microsoft window. I would appreciate some advice on how to trace what is wrong. Here's what I have tried:
Inserted try-catch in my main window class:
public MainWindow()
{
try
{
MessageBox.Show("Before InitComp()");
InitializeComponent();
MessageBox.Show("Before Sub1()");
Subroutine1();
MessageBox.Show("Before Sub2()");
Subroutine2();
... etc ...
}
catch (Exception ex)
{ ... code for MessageBox display error here ... }
}
The idea is to try to isolate which part of the startup sequence is crashing, but the first debug message "Before InitComp()" does not even show up. So it seems the app is crashing even before starting my code.
How should I go about debugging this problem?
In your App.xaml header, add:
<Application DispatcherUnhandledException="App_DispatcherUnhandledException" />
and in your App.xaml.cs, add something like:
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs args)
{
log.Fatal("An unexpected application exception occurred", args.Exception);
MessageBox.Show("An unexpected exception has occurred. Shutting down the application. Please check the log file for more details.");
// Prevent default unhandled exception processing
args.Handled = true;
Environment.Exit(0);
}
Old school approach: A hard crash like that is probably bubbling out to something you can see via Event Viewer in Windows. Have you checked there yet? A lot of times this tells me the answer without any extra trouble.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With