Visual Studio 2015 unexpectedly breaking on handled exceptions

谁说胖子不能爱 提交于 2019-12-05 10:10:36

There is a special case for this exception, which I am guessing applies here. From the docs:

AccessViolationException and try/catch blocks

Starting with the .NET Framework 4, AccessViolationException exceptions thrown by the common language runtime are not handled by the catch statement in a structured exception handler if the exception occurs outside of the memory reserved by the common language runtime. To handle such an AccessViolationException exception, you should apply the HandleProcessCorruptedStateExceptionsAttribute attribute to the method in which the exception is thrown. This change does not affect AccessViolationException exceptions thrown by user code, which can continue to be caught by a catch statement. For code written for previous versions of the .NET Framework that you want to recompile and run without modification on the .NET Framework 4, you can add the element to your app's configuration file. Note that you can also receive notification of the exceptions if you have defined a handler for the AppDomain.FirstChanceException or AppDomain.UnhandledException event.

As the docs say, the solution is to add the HandleProcessCorruptedStateExceptionsAttribute to the Start() method. If not possible (e.g., this is supplied via a library), I'm guessing you can add a method that wraps the call and add the attribute to that wrapping method.

obenda

You can see the answer in the following link How to handle AccessViolationException

For many reasons, in .NET 4.0 the runtime handles some exceptions as Windows Structured Error Handling (SEH) errors as indicators for Corrupted State, and those can not be caught as regular exceptions.

Enjoy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!