I have a WPF app that has a WindowsFormsHost in which a 3rd party WinForms control is hosted. Sometimes, because of a bug in the 3rd party WinForms control I get a NullReferenceException
.
Although I had set up a DispatcherUnhandledException
handler I can't catch the exception there and continue the execution.
Only in the AppDomain.CurrentDomain.UnhandledException
handler I can "catch" it but I cannot do much from then on, the application simply exits.
Then I found a stackoverflow question (with an answer; can't find it now) which stated to try to do this :
System.Windows.Forms.Application.ThreadException += (sender, args) => { /* Catch it here */};
System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
That didn't help either because the (inline) handler did not get called ever.
Am I going the wrong way?