vb.net 第一次机会例外

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2020374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:35:09  来源:igfitidea点击:

A first chance exception

vb.netvisual-studiowindows-7

提问by Night Walker

I have a project that runs perfect under windows xp.

我有一个在 windows xp 下完美运行的项目。

Now I have tried to run it under Windows 7 and got there a lot of exceptions under Immediate window.

现在我尝试在 Windows 7 下运行它,并在立即窗口下出现了很多异常。

A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
A first chance exception of type 'System.ArgumentException' occurred in LP_Wizard.exe
A first chance exception of type 'System.NullReferenceException' occurred in LP_Wizard.exe
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe

Any idea what wrong with that Microsoft.VisualBasic.dllin windows 7 and how i correct that problem ?

知道Microsoft.VisualBasic.dll在 Windows 7 中有什么问题 以及我如何纠正这个问题吗?

Thanks a lot for help .

非常感谢您的帮助。

回答by Marcus Andrén

If you want to pinpoint where the exceptions are occurring, you can select the Debug->Exceptions menu item, and in the dialog that appears, check the first checkbox for "Common Language Runtime Exceptions". This will make the debugger break as soon as an exception occurs instead of only breaking on unhandled exceptions.

如果要查明发生异常的位置,可以选择 Debug->Exceptions 菜单项,然后在出现的对话框中,选中“Common Language Runtime Exceptions”的第一个复选框。这将使调试器在异常发生时立即中断,而不是仅在未处理的异常时中断。

This is also one reason why it is generally a bad idea to catch generic exceptions unless you are clearly logging the information caught.

这也是为什么除非您清楚地记录捕获的信息,否则捕获通用异常通常是一个坏主意的原因之一。

回答by Adrian Clark

What is happening is the debugger can "see" exceptions as soon as they are raised (hence the "first chance") before any catchblock is hit. Any exception which is not handled by a catchblock is considered a "second chance" exception and will break normally.

正在发生的事情是调试器可以在任何catch块被命中之前一旦引发异常(因此是“第一次机会”)就可以“看到”异常。任何未被catch块处理的异常都被视为“第二次机会”异常并且会正常中断。

If these exceptions aren't stopping the running of your application because they are unhandled then you are probably OK. Most of the time the exception is handled by code and this isn't a problem. The output is simply Visual Studio letting you know the exceptions were raised.

如果这些异常没有因为未处理而停止应用程序的运行,那么您可能没问题。大多数时候异常是由代码处理的,这不是问题。输出只是 Visual Studio,让您知道引发了异常。

See the "Avoiding first chance exception messages when the exception is safely handled" question for some methods to reduce this if there are too many to ignore.

请参阅“安全处理异常时避免第一次机会异常消息”问题,了解一些方法,以在有太多需要忽略的情况下减少这种情况。

回答by fupsduck

Are your in the debugger? Are these exceptions your program is handling? If so you need to find a setting that tells VB to supress warning you of handled exceptions. Maybey this was set when installed on XP but not when you installed on W7. See if this helps:

你在调试器中吗?这些异常是您的程序正在处理的吗?如果是这样,您需要找到一个设置,告诉 VB 禁止警告您处理的异常。也许这是在 XP 上安装时设置的,而不是在 W7 上安装时设置的。看看这是否有帮助:

http://www.helixoft.com/blog/archives/24

http://www.helixoft.com/blog/archives/24