我有一个 WPF 应用程序,一旦我将它安装到没有安装开发环境的机器上,它就会崩溃——如果这是一个骗子,我欢迎关闭,但我的 search-fu 没有找到等效的问题。看来我得到了 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();
}
希望我能以这种方式得到我需要的东西。谢谢您的帮助!