Description
Related: dotnet/android#4877
Related: dotnet/android#4864
Related: https://xamarinhq.slack.com/archives/C03CEGRUW/p1593198033319900
Related: https://files.slack.com/files-pri/T03C6CW9H-F0164ULFMEE/image.png
Xamarin.Android v10.x uses the mono/mono/2020-02 branch, and uses the System.Diagnostics.Debugger.Mono_UnhandledException()
internal call when a debugger is attached, in order to simulate the first chance notification within the debugger.
Debugger.Mono_UnhandledException()
does not exist in .NET 5 mono. Consequently, when an exception is thrown in a .NET 5 Xamarin.Android app, the debugger "first chance notification" behavior differs.
As such, when an exception is thrown and not caught, there is no "first chance" notification, nor is there a "last chance" notification. Instead, execution continues, the entire call stack is unwound, and then the exception is visible within the debugger.
This might be a Glorious Opportunity to rework how exceptions work within Xamarin.Android apps when a debugger is attached. dotnet/android#4877 describes the current state of affairs, and it's "not good." In particular, current behavior is that when a managed exception is caught while the debugger is attached, when execution continues mono will unwind stack frames, without allowing execution to return to Java code.
This basically means that if you have a Managed > Java > Managed callstack transition, the process is effectively unusable if the rightmost frame throws an exception while the process is being debugged.
(Not using a debugger results in "sane" exception handling, but means you don't have a debugger…)