how to handle System.AccessViolationException occurred in System.Windows.Forms.dll?

1.6k Views Asked by At

i am making an windows application in c#...

and for that i am using sqlexpress for database and componentfactory's krypton tools for UI components...

i am running this application on x86 plateform...

application works fine..but sometimes when i close the form System.AccessViolationException in System.Windows.Forms.dll comes on dispose...

i added <legacyCorruptedStateExceptionsPolicy enabled="true" /> into app.config under <runtime></runtime>...

i also added [HandleProcessCorruptedStateExceptions] upon main function and dispose...

still this error not solved...

i am attaching an screen shot image..kindly look at image also..
thanks in advance..

enter image description here

1

There are 1 best solutions below

1
On BEST ANSWER

Even if you set HandleProcessCorruptedStateExceptions attribute, still you need to wrap your code in try catch

[HandleProcessCorruptedStateExceptions] 
public void TheFunction()
{ 
   try
   {
       // Catch any exceptions in your code
   }
   catch (Exception e) 
   {
        System.Console.WriteLine(e.Message); 
   } 
}