如何从用户的计算机获取有用的WPF .NET错误信息?

mmr*_*mmr 15 .net c# wpf xamlparseexception

我有一个都崩溃了,一旦我得到它在没有开发环境installed--如果这是一个傻瓜,我是欢迎的封罐机WPF应用程序,但我我的搜索福未能找到一个等效的问题.我似乎得到了一个XamlParseException,但没有比这更有用了.我需要获得有用的信息.

浏览Windows 7事件日志会给我这个错误日志:

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
Run Code Online (Sandbox Code Playgroud)

我检查了那些目录,第一个目录不存在,而第二个目录包含一个只列出加载的dll的wer文件.

我可以在我的测试机器上安装一个开发环境,但是它无法成为一台测试机器而我又回到原点.我没有在安装了开发环境时遇到此错误,因此我对如何获得详细,有用的错误消息感到茫然.

编辑:建立@Alastair Pitts的评论如下,这是我填写异常处理的方式:

    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();
    }
Run Code Online (Sandbox Code Playgroud)

希望我能以这种方式得到我需要的东西.谢谢您的帮助!

Ala*_*tts 15

我将使用的过程是在app域中处理UnhandledException 事件.

完成后,您有很多选择.将异常记录到文件中,将其序列化以供以后检查,显示带有异常消息的对话框.

编辑:XamlParseException在创建主窗口时发生.这意味着正在调用该窗口的构造函数.如果在该构造函数中执行任何逻辑,则任何结果异常都将抛出一个XamlParseException.据我所知,UnhandledException处理程序仍将捕获此异常.

UnhandledException在WPF中连接事件,请在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" />
Run Code Online (Sandbox Code Playgroud)

然后在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;
    }
}
Run Code Online (Sandbox Code Playgroud)

MSDN