我有一个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
我已经检查了这些目录,第一个目录不存在,而第二个目录包含一个wer文件,其中只列出了加载的dlls。我可以在我的测试机上安装开发环境,但这样它就不能作为测试机使用,我又回到了原点。我在安装开发环境时没有遇到此错误,因此我不知道如何获得详细和有用的错误消息。
编辑:在@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();
}
希望这样我能得到我所需要的东西。感谢您的帮助!