DotnetRuntimeBootstrapper icon indicating copy to clipboard operation
DotnetRuntimeBootstrapper copied to clipboard

`AppDomain.CurrentDomain.UnhandledException` doesn't get called

Open andyld97 opened this issue 2 years ago • 6 comments

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.

andyld97 avatar Feb 07 '22 14:02 andyld97

Still can't figure it out. Created a question here: https://github.com/dotnet/runtime/discussions/64942

Tyrrrz avatar Feb 07 '22 21:02 Tyrrrz

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.

Tyrrrz avatar Nov 30 '22 18:11 Tyrrrz

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. 😒

Tyrrrz avatar Nov 30 '22 19:11 Tyrrrz

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) 🤔

andyld97 avatar Nov 30 '22 20:11 andyld97

Yeah, you're right. I was focused on my case where most of these exceptions do actually happen on startup.

Tyrrrz avatar Dec 01 '22 08:12 Tyrrrz

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.

Tyrrrz avatar Dec 01 '22 09:12 Tyrrrz