Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET app terminates without getting into AppDomain.UnhandledException

Tags:

.net

exception

I have an app which terminates unexpectedly sometimes in spite of existence of handlers for AppDomain.CurrentDomain.UnhandledException, Application.Current.DispatcherUnhandledException, TaskScheduler.UnobservedTaskException events.

This is a WPF app with many P/Invoke interop code. I've created "safety-net" with handlers for all "last resort" events (see above). But the app still fails with standard Windows error dialog missing all my handler.

What can be a cause for .net app termination and avoiding AppDomain.CurrentDomain.UnhandledException ?

Can an exception in unmanaged thread be such a cause? If so what can I do with it?

like image 349
Shrike Avatar asked Apr 29 '26 00:04

Shrike


1 Answers

The CLR cannot magically inject unhandled exception handling into native pinvoked code when that code itself doesn't take care of it. Particularly any kind of hardware exception like AccessViolation in a thread that the CLR doesn't know about will terminate the app without a diagnostic. You'll need to work with the owner or author of that code to improve the reliability and maintainability of that code.

like image 103
Hans Passant Avatar answered May 01 '26 15:05

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!