I have a .NET application (service) that consists of C# and C++ code.
"Crashes" (i.e. System.AccessViolationException and other Corrupted State Exceptions) in the C++ Code will be ("non-") handled correctly, they will directly lead to my AppDomain.CurrentDomain.UnhandledException handler (which logs) and then the application will terminate, writing a WER dump file if so configured (which it is).
For this application, I have determined that System.NullReferenceException is always a bug, especially since some C++/CLI Access Violation bugs will report this one instead of an AV.
Is there any way to make .NET not catch a NullReferenceException on an exception boundary (my OnTimer callback in this case) but instead directly terminate the app, without unwinding the stack, basically "jumping" directly to AppDomain.CurrentDomain.UnhandledException?
The fact that
FirstChanceExceptionis actually a "simple" global exception filter got me on the track (it remains to be seen whether it's the "right" track):We already have exception filters in CLI.
If one has the luxury of working in C# 6, it's as simple as:
And for those of us (like me) stuck on earlier versions, we can route the filtering through VB.NET via a delegate / lambda:
with VB as such (bear with me, VB.NET is far from a language I'm fluent in):
Obviously, to make it work you need some more configuration rigging, but that seems to be exactly what I want. :-)