1 year ago
#371472
Aswini Y
Unable to handle exception thrown from unmanaged/native code in managed code(c# wpf) such as out of memory exceptions globally
In my windows C#.net application, using some third party libraries which are of c++. and in few cases, I am unable to catch the exceptions thrown from those c++ libraries, I have tried all the below global exception handlers, but still unable to catch the exception.
AppDomain.CurrentDomain.UnhandledException
OnUnobservedTaskException
Current.DispatcherUnhandledException
Dispatcher.UnhandledException
Current.Dispatcher.UnhandledExceptionFilter
System.Windows.Forms.Application.ThreadException
The application is getting crashed with out any information logged in file, but putting an entry in Event viewer with application error like below:
Faulting module name: ucrtbase.dll, version: 10.0.19041.789, time stamp: 0x82dc99a2 Exception code: 0xc0000409
Also tried Marking the RuntimeCompatibilityAttribute(WrapNonExceptionThrows = true)
in the AssmblyInfo file.
<legacyCorruptedStateExceptionsPolicy enabled="true" />
in App.config file.
And Decorate the method with the HandleProcessCorruptedStateExceptions
attribute
Also tried inline with the method which is calling third part method causing exception by placing Empty catch block
still unable to catch native exceptions.
I have so many calls for third party methods in many places, so I am not sure to handle all of them with Try catch. So I need a global handler to log the exception but not crash the application.
My requirement here is to catch the native exceptions globally and log to my log file with out adding entry in event viewer.
c#
exception
unmanaged
0 Answers
Your Answer