DotnetRuntimeBootstrapper
DotnetRuntimeBootstrapper copied to clipboard
`AppDomain.CurrentDomain.UnhandledException` doesn't get called
Version
ver 2.1.0
Details
According to #23 I've made this little project: UnhandledExceptionsRepro.zip
The problem is that the AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
event handler doesn't get called when using DotnetRuntimeBootstrapper.
I think the sample app is very easy to understand, so I don't think it needs more explanation here (I also added comments).
Steps to reproduce
Just click the button and read the comments.
Still can't figure it out. Created a question here: https://github.com/dotnet/runtime/discussions/64942
Thought of a potential workaround to get the exception out: if the target assembly fails to run even after all prerequisites have been resolved, run it with dotnet
CLI and get the output from stderr (which should contain the error message). No extra overhead on the hot/happy path.
Nevermind, it appears you can't use dotnet
CLI once the application host is already initialized. And unfortunately you can't uninitialize/unload the host. 😒
But I think even if your idea would work, we would only get those exceptions at the startup? Or am I wrong? Because the actual problem is more like getting the unhandeld exception somewhere in your app when the user does something unexpected (if you know what I mean) 🤔
Yeah, you're right. I was focused on my case where most of these exceptions do actually happen on startup.
I found a way to at least show an error message to the user, although it still lacks the original exception message and stacktrace. Should at least not fail silently this way.