我怎样才能从用户的机器有用的WPF .NET错误信息? [英] How can I get useful WPF .NET error information from a user's machine?

查看:382
本文介绍了我怎样才能从用户的机器有用的WPF .NET错误信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有崩溃的,一旦我得到它的机器上一个WPF应用程序没有一个开发环境安装 - 如果这是一个傻瓜,我欢迎收盘,但我我的搜索福未能找到一个等效问题。看来,我得到一个XamlParseException,但没有什么比这更有益。我需要得到有用的信息。

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.

通过Windows 7的事件日志去给我这个错误日志:

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

我检查这些目录,第一不存在,而第二个包含WER文件,该文件仅列出加载的DLL。

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.

编辑:关建设下面@Alastair皮茨评论,这里就是我填写了异常处理:

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!

推荐答案

我会使用的过程来处理 UnhandledException 事件

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.

编辑: XamlParseException 的发生。这意味着,该窗口的构造函数被调用。如果您在构造函数中执行任何逻辑,由此产生的任何异常都将抛出一个 XamlParseException 。这是我的理解是, UnhandledException 处理器仍然会捕获这个异常。

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.

要挂钩的<$ C $在WPF C> UnhandledException 事件,添加事件联播在你的App.xaml

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" />



然后添加一个方法你app.cs

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

这篇关于我怎样才能从用户的机器有用的WPF .NET错误信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆