Click here to Skip to main content
Click here to Skip to main content

Tagged as

CLR is Not Allowed Managed Code to Catch Access Violations and Other Corrupted State Exceptions

, 30 Jan 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
CLR is not allowed managed code to catch access violations and other corrupted state exceptions

Introduction

When we use .NET 4.0 and above to make an application, then CLR is not allowed managed code to catch access violations and other corrupted state exceptions.

Using the Code

To allow common language runtime, managed code to catch access violations and other corrupted state exceptions, we need to add configuration or we can also set attribute to method to handle corrupted state exceptions.

Use this configuration in your configuration file to allow CLR to handle COM exceptions like corrupted state exceptions:

<configuration>
   <runtime>
      <legacyCorruptedStateExceptionsPolicy enabled="true" />
   </runtime>
</configuration>

This configuration will set for application level, means your code within application can handle COM exception (unmanaged code) but if you want to set any method to handle corrupted state exceptions, you need to write attribute to top of method. This is a code example how we can use attribute:

[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptionsAttribute]
void ReadExcel()
{
try
{
// write code to read excel file
}
catch(Exception ex)
{
// now it will handle exception
}
} 

When I was creating an application in .NET 4.0, then I had to read Excel file. Then I encountered that problem. I had written try catch block in side that method which contains code to read Excel file but my try catch was not working and application got crashed then I reported this issue in Microsoft Visual Studio bug forum, but I did not get any good response from them. Then I searched on the internet and I found this post.

History

  • 30th January, 2014: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Shriniwas Shukla
Software Developer
India India
No Biography provided
Follow on   Twitter

Comments and Discussions

 
GeneralMy vote of 3 PinprofessionalVinicius G. D. Menezes31-Jan-14 5:27 
QuestionUseful... but a bit misleading PinprofessionalNicholas Marty31-Jan-14 0:07 
GeneralMy vote of 5 PinmemberItay Gal30-Jan-14 23:19 
GeneralMy vote of 5 PinmemberKlaus Luedenscheidt30-Jan-14 18:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 30 Jan 2014
Article Copyright 2014 by Shriniwas Shukla
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid