How can I get useful WPF .NET error information from a user's machine?

后端 未结 4 1182
日久生厌
日久生厌 2020-12-15 07:14

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

4条回答
  •  醉梦人生
    2020-12-15 07:57

    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

    
    

    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

提交回复
热议问题