热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

IhaveaWPFapplicationthatscrashingonceIgetitontomachinesthatdonothaveadevelopment

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.

我有一个WPF应用程序崩溃了一旦我把它安装到没有安装开发环境的机器上 - 如果这是一个骗局,我欢迎关闭,但我的搜索功能未能找到一个相同的问题。看来我得到了一个XamlParseException,但没有比这更有用了。我需要获得有用的信息。

Going through the Windows 7 event logs gives me this error log:

浏览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

I've checked those directories, and the first doesn't exist, while the second contains a wer file that just lists the loaded dlls.

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

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.

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

EDIT: building off of @Alastair Pitts' comment below, here's how I filled out the exception handling:

编辑:在下面建立@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();
    }

Hopefully, I'll get what I need this way. Thanks for the help!

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

4 个解决方案

#1


14  

The procedure I would use is to handle the UnhandledException event in the app domain.

我将使用的过程是处理应用程序域中的UnhandledException事件。

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.

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

EDIT: 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.

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

To hook up the UnhandledException event in WPF, add the event hookup in your app.xaml

要在WPF中连接UnhandledException事件,请在app.xaml中添加事件连接


which then adds a method in your app.cs

然后在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

MSDN

#2


2  

In addition to having an unhandled exception event handler that logs the stack trace, it is also useful to look at the crash dumps being generated on the repro machine. You mentioned it's Windows 7, so you can look for corresponding crash dumps in the following ways:

除了具有记录堆栈跟踪的未处理异常事件处理程序之外,查看在repro计算机上生成的故障转储也很有用。您提到它是Windows 7,因此您可以通过以下方式查找相应的故障转储:

  1. Control Panel -> All Control Panel Items -> Action Center -> "View problems to report" link underneath the Maintenance/"Check for solutions to unreported problems" area. This brings up a list of applications that have crashed and you can drill down into them to find the dump files and information. Look for the "View a temporary copy of these files" link in the bottom left of the problem technical details. This will extract the dump files and show them to you in an explorer window.

    控制面板 - >所有控制面板项目 - >操作中心 - >“查看要报告的问题”链接位于维护/“检查未报告问题的解决方案”区域下方。这将显示已崩溃的应用程序列表,您可以深入查看它们以查找转储文件和信息。查找问题技术详细信息左下角的“查看这些文件的临时副本”链接。这将提取转储文件并在资源管理器窗口中显示给您。

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

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

WER seems to keep it's crash dumps underneath that directory, so what I do is a dir /s/b for part of the app name that I know will be there. For example, I made a on purpose crashy app that i called crashyapp.exe:

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
    
That directory contains the hdmp and mdmp files for the crash. Time to get a debugger attached!

#3


1  

Exception logging (as in the answer from Alastair Pitts) would be a help in zeroing in on the source of the error.

异常记录(如Alastair Pitts的答案)将有助于归零错误的来源。

The presence of XamlParse on line P9 suggests that there may be a problem initializing a control or window from the XAML description. There may be an assembly referenced by the XAML which was not found on the target computer, or did not match the signature in the XAML.

在P9行上存在XamlParse表明从XAML描述初始化控件或窗口可能存在问题。可能存在由XAML引用的程序集,该程序集在目标计算机上找不到,或者与XAML中的签名不匹配。

Edit:

编辑:

XAML parsing occurs in InitializeComponent() which is called in the constructor of the window or control

XAML解析发生在InitializeComponent()中,它在窗口或控件的构造函数中调用

#4


0  

In addition to Alistair's answer, it's the InnerException that gave me the clues I was looking for:

除了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();
    }
}

推荐阅读
  • python3 nmap函数简介及使用方法
    本文介绍了python3 nmap函数的简介及使用方法,python-nmap是一个使用nmap进行端口扫描的python库,它可以生成nmap扫描报告,并帮助系统管理员进行自动化扫描任务和生成报告。同时,它也支持nmap脚本输出。文章详细介绍了python-nmap的几个py文件的功能和用途,包括__init__.py、nmap.py和test.py。__init__.py主要导入基本信息,nmap.py用于调用nmap的功能进行扫描,test.py用于测试是否可以利用nmap的扫描功能。 ... [详细]
  • Metasploit攻击渗透实践
    本文介绍了Metasploit攻击渗透实践的内容和要求,包括主动攻击、针对浏览器和客户端的攻击,以及成功应用辅助模块的实践过程。其中涉及使用Hydra在不知道密码的情况下攻击metsploit2靶机获取密码,以及攻击浏览器中的tomcat服务的具体步骤。同时还讲解了爆破密码的方法和设置攻击目标主机的相关参数。 ... [详细]
  • YOLOv7基于自己的数据集从零构建模型完整训练、推理计算超详细教程
    本文介绍了关于人工智能、神经网络和深度学习的知识点,并提供了YOLOv7基于自己的数据集从零构建模型完整训练、推理计算的详细教程。文章还提到了郑州最低生活保障的话题。对于从事目标检测任务的人来说,YOLO是一个熟悉的模型。文章还提到了yolov4和yolov6的相关内容,以及选择模型的优化思路。 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 本文介绍了Hyperledger Fabric外部链码构建与运行的相关知识,包括在Hyperledger Fabric 2.0版本之前链码构建和运行的困难性,外部构建模式的实现原理以及外部构建和运行API的使用方法。通过本文的介绍,读者可以了解到如何利用外部构建和运行的方式来实现链码的构建和运行,并且不再受限于特定的语言和部署环境。 ... [详细]
  • 如何搭建Java开发环境并开发WinCE项目
    本文介绍了如何搭建Java开发环境并开发WinCE项目,包括搭建开发环境的步骤和获取SDK的几种方式。同时还解答了一些关于WinCE开发的常见问题。通过阅读本文,您将了解如何使用Java进行嵌入式开发,并能够顺利开发WinCE应用程序。 ... [详细]
  • 本文介绍了使用cacti监控mssql 2005运行资源情况的操作步骤,包括安装必要的工具和驱动,测试mssql的连接,配置监控脚本等。通过php连接mssql来获取SQL 2005性能计算器的值,实现对mssql的监控。详细的操作步骤和代码请参考附件。 ... [详细]
  • 本文介绍了在Mac上安装Xamarin并使用Windows上的VS开发iOS app的方法,包括所需的安装环境和软件,以及使用Xamarin.iOS进行开发的步骤。通过这种方法,即使没有Mac或者安装苹果系统,程序员们也能轻松开发iOS app。 ... [详细]
  • 本文讨论了如何使用Web.Config进行自定义配置节的配置转换。作者提到,他将msbuild设置为详细模式,但转换却忽略了带有替换转换的自定义部分的存在。 ... [详细]
  • 本文介绍了在CentOS 6.4系统中更新源地址的方法,包括备份现有源文件、下载163源、修改文件名、更新列表和系统,并提供了相应的命令。 ... [详细]
  • iOS开发Debug和Release的理解
    2019独角兽企业重金招聘Python工程师标准参考:http:blog.csdn.netmad1989articledetails406580331&# ... [详细]
  • Windows下配置PHP5.6的方法及注意事项
    本文介绍了在Windows系统下配置PHP5.6的步骤及注意事项,包括下载PHP5.6、解压并配置IIS、添加模块映射、测试等。同时提供了一些常见问题的解决方法,如下载缺失的msvcr110.dll文件等。通过本文的指导,读者可以轻松地在Windows系统下配置PHP5.6,并解决一些常见的配置问题。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 【Windows】实现微信双开或多开的方法及步骤详解
    本文介绍了在Windows系统下实现微信双开或多开的方法,通过安装微信电脑版、复制微信程序启动路径、修改文本文件为bat文件等步骤,实现同时登录两个或多个微信的效果。相比于使用虚拟机的方法,本方法更简单易行,适用于任何电脑,并且不会消耗过多系统资源。详细步骤和原理解释请参考本文内容。 ... [详细]
  • iOS超签签名服务器搭建及其优劣势
    本文介绍了搭建iOS超签签名服务器的原因和优势,包括不掉签、用户可以直接安装不需要信任、体验好等。同时也提到了超签的劣势,即一个证书只能安装100个,成本较高。文章还详细介绍了超签的实现原理,包括用户请求服务器安装mobileconfig文件、服务器调用苹果接口添加udid等步骤。最后,还提到了生成mobileconfig文件和导出AppleWorldwideDeveloperRelationsCertificationAuthority证书的方法。 ... [详细]
author-avatar
Jackson-過時間
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有