簡體   English   中英

如何從用戶的計算機獲取有用的WPF .NET錯誤信息?

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

我有一個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

我檢查了那些目錄,第一個目錄不存在,而第二個包含一個只列出加載的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();
    }

希望我能以這種方式得到我需要的東西。 謝謝您的幫助!

我將使用的過程是在app域中處理UnhandledException 事件

完成后,您有很多選擇。 將異常記錄到文件中,將其序列化以供以后檢查,顯示帶有異常消息的對話框。

編輯:在創建主窗口時發生XamlParseException 這意味着正在調用該窗口的構造函數。 如果在該構造函數中執行任何邏輯,則任何生成的異常都將拋出XamlParseException 據我所知, UnhandledException處理程序仍將捕獲此異常。

要在WPF中連接UnhandledException事件,請在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中添加一個方法

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

除了具有記錄堆棧跟蹤的未處理異常事件處理程序之外,查看在repro計算機上生成的故障轉儲也很有用。 您提到它是Windows 7,因此您可以通過以下方式查找相應的故障轉儲:

  1. 控制面板 - >所有控制面板項目 - >操作中心 - >“查看要報告的問題”鏈接位於維護/“檢查未報告問題的解決方案”區域下方。 這將顯示已崩潰的應用程序列表,您可以深入查看它們以查找轉儲文件和信息。 查找問題技術詳細信息左下角的“查看這些文件的臨時副本”鏈接。 這將提取轉儲文件並在資源管理器窗口中顯示給您。

  2. cd / d%ProgramData%\\ Microsoft \\ Windows \\ WER。

WER似乎保留了該目錄下面的崩潰轉儲,所以我所做的是一個dir / s / b,我知道將在那里使用部分應用程序名稱。 例如,我制作了一個故意崩潰的應用程序,我稱之為crashyapp.exe:

C:\ProgramData\Microsoft\Windows\WER>dir /s/b *crashy*
C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_crashyapp.exe_56f8d710d72e31d822d6b895c5c43a18d34acfa1_cab_2823e614
該目錄包含崩潰的hdmp和mdmp文件。 是時候連接調試器了!

異常記錄(如Alastair Pitts的答案)將有助於歸零錯誤源。

在P9行上存在XamlParse表明從XAML描述初始化控件或窗口可能存在問題。 可能存在由XAML引用的程序集,該程序集在目標計算機上找不到,或者與XAML中的簽名不匹配。

編輯:

XAML解析發生在InitializeComponent()中,它在窗口或控件的構造函數中調用

除了Alistair的答案之外,還有InnerException給了我尋找的線索:

public partial class App : Application {
    void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) {
        Exception ex = e.Exception;
        Exception ex_inner = ex.InnerException;
        string msg = ex.Message + "\n\n" + ex.StackTrace + "\n\n" +
            "Inner Exception:\n" + ex_inner.Message + "\n\n" + ex_inner.StackTrace + "\n\n" + 
            Utils.RegistryVersion();
        MessageBox.Show(msg, "Drop Print Batch Application Halted!", MessageBoxButton.OK);
        Utils.MailReport(msg);
        e.Handled = true;
        Application.Current.Shutdown();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM