简体   繁体   English

Windows Forms应用程序中未处理的异常

[英]Unhandled exception in Windows Forms app

I have a Windows Forms application. 我有Windows窗体应用程序。 It loads assemblies with the extension .Plugin.dll with Assembly.LoadFile. 它使用Assembly.LoadFile加载扩展名为.Plugin.dll的程序集。 One of these "plugins" calls into another assembly dll. 这些“插件”之一调用另一个程序集dll。 That dll eventually throws a ValidationException exception. 该dll最终引发ValidationException异常。 The method that throws the exception is in a class that inherits from IDataErrorInfo. 引发异常的方法位于从IDataErrorInfo继承的类中。 This class is a class that is contained in a Linq to SQL class (.dbml). 此类是Linq to SQL类(.dbml)中包含的类。 In the "plugin" I call DataContext.SubmitChanges. 在“插件”中,我称为DataContext.SubmitChanges。 This is wrapped in a try/catch block. 它包装在try / catch块中。 This causes my business logic to validate the data before submitting to the database in the OnValidate override. 这使我的业务逻辑先验证数据,然后再以OnValidate替代提交给数据库。 The result that I see is that after the ValidationExeption is thrown, the debugger stops at the bottom of the OnValidate method indicating that an unhandled exception has occured. 我看到的结果是,在引发ValidationExeption之后,调试器在OnValidate方法的底部停止,指示发生了未处理的异常。 If I continue to run the app my catch block is executed. 如果我继续运行该应用程序,则执行catch块。 That is what I wanted in the first place, but why am i getting an unhandled exception when it truly is handled? 那是我最初想要的,但是为什么在真正处理完异常后却出现未处理的异常?

I am 99% sure your "real" exception causing this is indeed unhandled -this is what the Debugger tells you at first place, and he is generally right. 我99%确信导致这种情况的“真正”异常确实没有得到处理-这是调试器首先告诉您的,他通常是正确的。

When you continue to run the App in VS after that, it is not actually what would happen when you will execute your exe out of the debugger. 此后,当您继续在VS中运行该应用程序时,从调试器中执行exe并不会真正发生。 In fact, the debugger notifies you first of the unhandled exception, and then continues some pending logic if any (that's why you see you ValidationException error). 实际上,调试器会首先将未处理的异常通知您,然后继续一些未决的逻辑(如果有的话)(这就是为什么您看到ValidationException错误)。 But the unhandled exception is still there. 但是未处理的异常仍然存在。 I don't exactly know the details and causes of this behavior, but I noticed this many times. 我不完全了解这种行为的细节和原因,但是我注意到了很多次。

You have to catch the precise error at the precise place where the unhandledexception is thrown after you identify it. 识别出未处理的异常后,您必须在引发未处理异常的确切位置捕获准确的错误。 Maybe posting your code sample would help. 也许发布您的代码示例会有所帮助。

Firstly, is the plugin in the same AppDomain? 首先,该插件是否在同一AppDomain中?

Secondly, it sounds to be like you have your debugger to "Break when exception is thrown" rather than "Break when exception is user-unhandled". 其次,听起来好像您的调试器是“抛出异常时中断”,而不是“用户未处理异常时中断”。

In VS.NET, go to Debug --> Exceptions... 在VS.NET中,转到调试->异常...

Expand the "Common Language Runtime Exceptions" node and see if any are ticked. 展开“公共语言运行时异常”节点,查看是否有任何勾选。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows Forms 未处理的异常崩溃 - Windows Forms Unhandled Exception Crash Windows窗体未处理 - 异常对话框 - Windows Forms Unhandled-Exception Dialog Windows服务中未处理的异常 - Unhandled Exception in Windows Service 应用程序崩溃而未调用未处理的异常方法Windows Phone 8 - App Crashing without calling Unhandled Exception method Windows Phone 8 System.Windows.Forms.dll中发生类型为'System.ArgumentException'的未处理异常 - an unhandled exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll System.Windows.Forms.d中发生了类型为'System.ObjectDisposedException'的未处理异常 - An unhandled exception of type 'System.ObjectDisposedException' occurred in System.Windows.Forms.d System.Windows.Forms.dll中发生了类型为'System.StackOverflowException'的未处理异常 - An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll “System.Windows.Forms.dll中发生了'System.StackOverflowException'类型的未处理异常” - “An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll” 生成报告导致在system.windows.forms.dll中发生类型为'system.stackoverflowexception'的未处理异常 - Generating report results in an unhandled exception of type 'system.stackoverflowexception' occurred in system.windows.forms.dll 错误:System.Windows.Forms.dll中发生未处理的“System.BadImageFormatException”类型异常 - Error: An unhandled exception of type 'System.BadImageFormatException' occurred in System.Windows.Forms.dll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM