views:

337

answers:

3

Hi all,

I have a WPF application that's crashing once I get it onto machines that do not have a development environment installed-- if this is a dupe, I'm welcome to closing, but I my search-fu is failing to find an equivalent question. It appears that I'm getting a XamlParseException, but nothing more useful than that. I need to get useful information.

Going through the Windows 7 event logs gives me this error log:

Fault bucket , type 0
Event Name: CLR20r3
Response: Not available
Cab Id: 0

Problem signature:
P1: MyApp.exe
P2: 1.0.0.0
P3: 4b88323d
P4: PresentationFramework
P5: 3.0.0.0
P6: 4a174fbc
P7: 624f
P8: e1
P9: System.Windows.Markup.XamlParse
P10: 

Attached files:
C:\Users\Mark\AppData\Local\Temp\WER7DC.tmp.WERInternalMetadata.xml

These files may be available here:
C:\Users\Mark\AppData\Local\Microsoft\Windows\WER\ReportArchive
 \AppCrash_generatortestbed_4fa7dff09a9e893eb675f488392571ced4ac8_04ef1100

Analysis symbol: 
Rechecking for solution: 0
Report Id: cd55060c-271f-11df-b6ff-001e52eefb8e
Report Status: 1

I've checked those directories, and the first doesn't exist, while the second contains a wer file that just lists the loaded dlls.

I could install a development environment on my test machine, but then it fails to be a test machine and I'm back to square one. I don't get this error with a dev environment installed, so I'm at a loss about how to get a verbose, useful error message.

EDIT: building off of @Alastair Pitts' comment below, here's how I filled out the exception handling:

    private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) {
        Exception theException = e.Exception;
        string theErrorPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\GeneratorTestbedError.txt";
        using (System.IO.TextWriter theTextWriter = new System.IO.StreamWriter(theErrorPath, true)){
            DateTime theNow = DateTime.Now;
            theTextWriter.WriteLine("The error time: " + theNow.ToShortDateString() + " " + theNow.ToShortTimeString());
            while (theException != null) {
                theTextWriter.WriteLine("Exception: " + theException.ToString());
                theException = theException.InnerException;
            }
        }
        MessageBox.Show("The program crashed.  A stack trace can be found at:\n" + theErrorPath);
        e.Handled = true;
        Application.Current.Shutdown();
    }

Hopefully, I'll get what I need this way. Thanks for the help!

+2  A: 

The procedure I would use is to handle the UnhandledException event in the app domain.

Once you have done that, you have a number of options. Logging the exception to a file, serialising it for later inspection, showing a dialog box with the exception message.

EDIT: XamlParseException's occur when your main window is being created. This means that the constructor of that window is being called. If you perform any logic in that constructor, any resulting exceptions will throw a XamlParseException. It is my understanding that the UnhandledException handler will still catch this exception.

To hook up the UnhandledException event in WPF, add the event hookup in your app.xaml

<Application 
   x:Class="DispatcherUnhandledExceptionSample.App"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   StartupUri="MainWindow.xaml"     
   DispatcherUnhandledException="App_DispatcherUnhandledException" />

which then adds a method in your app.cs

public partial class App : Application
{
    void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
    {
        // Process unhandled exception do stuff below

        // Prevent default unhandled exception processing
        e.Handled = true;
    }
}

MSDN

Alastair Pitts
If itis a XamlParseError, it appears that that error would happen before I could use any code, just in the drawing of the app window. Is there a way to track this exception before user code gets called? Or am I wrong about XamlParseErrors?
mmr
I've added a bit more stuff.
Alastair Pitts
Most helpful, I'll look into it. Thanks!
mmr
+1  A: 

Exception logging (as in the answer from Alastair Pitts) would be a help in zeroing in on the source of the error.

The presence of XamlParse on line P9 suggests that there may be a problem initializing a control or window from the XAML description. There may be an assembly referenced by the XAML which was not found on the target computer, or did not match the signature in the XAML.

Edit:

XAML parsing occurs in InitializeComponent() which is called in the constructor of the window or control

Doug Ferguson