-4

I wrote a window service which will convert files from XXX to XXX using DLL, but when system.accessviolationexception occurs i am not able to catch these exception even though i have try and catch block.

But after some time my service automatically crashes down and it will write the logs in event viewer.

Description: The process was terminated due to an unhandled exception. Exception Info: System.AccessViolationException

try 
{
    PDFNet.PDF.Convert.ToHtml(doc, htmlSourceFolderName, options);
} 
catch (System.AccessViolationException avex) 
  {
    logMgr.Error(avex.StackTrace);
  }
catch (Exception ex) 
{
    logMgr.Error(avex.StackTrace);
}

Is there any way so that i can get the desired result.

  • 4
    Showing us the appropriate code in question would be jolly helpful good sir. [mcve] –  Apr 19 '17 at 07:52
  • try { PDFNet.PDF.Convert.ToHtml(doc, htmlSourceFolderName, options); } catch(System.AccessViolationException avex) logMgr.Error(avex.StackTrace); ) catch(Exception ex) { logMgr.Error(avex.StackTrace); } – Venkatesh Venky Apr 19 '17 at 08:01
  • 1
    Possible duplicate of [Why AccessViolationException cannot be caught by .NET4.0](http://stackoverflow.com/questions/12581202/why-accessviolationexception-cannot-be-caught-by-net4-0) – Martin Costello Apr 19 '17 at 08:02
  • Is this an XY problem? Perhaps your p-invoke signature is incorrect? If you fix it then you won't get such exeptions –  Apr 19 '17 at 08:06
  • Is it possible if i use .NET 4.5 – Venkatesh Venky Apr 19 '17 at 08:07
  • .NET 4.0 and later are all bound by the same rules regarding catching `AccessViolationException` as far as I'm aware, especially as .NET 4.5 still runs within the .NET 4.0 _runtime_. – Martin Costello Apr 19 '17 at 08:17

1 Answers1

1

Catching AccessViolationException has not been possible in general since .NET 4.0 was released.

This is discussed here: https://stackoverflow.com/a/12581291/1064169

Community
  • 1
  • 1
Martin Costello
  • 9,672
  • 5
  • 60
  • 72