Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In .NET 4.0, the runtime handles certain exceptions raised as Windows Structured Error Handling (SEH) errors as indicators of Corrupted State. These Corrupted State Exceptions (CSE) are not allowed to be caught by your standard managed code. I won't get into the why's or how's here. Read this article about CSE's in the .NET 4.0 Framework:</p> <p><a href="http://msdn.microsoft.com/en-us/magazine/dd419661.aspx#id0070035" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/magazine/dd419661.aspx#id0070035</a></p> <p>But there is hope. There are a few ways to get around this:</p> <ol> <li><p>Recompile as a .NET 3.5 assembly and run it in .NET 4.0.</p></li> <li><p>Add a line to your application's config file under the configuration/runtime element: <code>&lt;legacyCorruptedStateExceptionsPolicy enabled="true|false"/&gt;</code></p></li> <li><p>Decorate the methods you want to catch these exceptions in with the <code>HandleProcessCorruptedStateExceptions</code> attribute. See <a href="http://msdn.microsoft.com/en-us/magazine/dd419661.aspx#id0070035" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/magazine/dd419661.aspx#id0070035</a> for details.</p></li> </ol> <hr> <p><strong>EDIT</strong></p> <p>Previously, I referenced a <a href="https://web.archive.org/web/20120104165841/http://connect.microsoft.com:80/VisualStudio/feedback/details/557105/unable-to-catch-accessviolationexception" rel="nofollow noreferrer">forum post</a> for additional details. But since Microsoft Connect has been retired, here are the additional details in case you're interested:</p> <p>From Gaurav Khanna, a developer from the Microsoft CLR Team</p> <blockquote> <p>This behaviour is by design due to a feature of CLR 4.0 called Corrupted State Exceptions. Simply put, managed code shouldnt make an attempt to catch exceptions that indicate corrupted process state and AV is one of them.</p> </blockquote> <p>He then goes on to reference the documentation on the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.exceptionservices.handleprocesscorruptedstateexceptionsattribute.aspx" rel="nofollow noreferrer">HandleProcessCorruptedStateExceptionsAttribute</a> and the above article. Suffice to say, it's definitely worth a read if you're considering catching these types of exceptions.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload