Commit 2ccdb27
authored
[Mono.Android] Fix UnhandledExceptionRaiser not firing in .NET 10 (#10966)
Context: dotnet/java-interop#1275
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2842209
dotnet/java-interop#1275 eliminated
`JNINativeWrapper.CreateDelegate()` from generated binding marshal
methods. The old code path routed exceptions through
`AndroidEnvironment.UnhandledException()`, which fires the
`UnhandledExceptionRaiser` event. The new code path calls
`JniRuntime.OnUserUnhandledException()`, which only calls
`SetPendingException()` and never invokes
`AndroidEnvironment.UnhandledException()`.
Fix by overriding `OnUserUnhandledException()` in `AndroidRuntime` to
call `AndroidEnvironment.TryRaiseUnhandledException()` before
delegating to the base implementation. If a subscriber sets `Handled =
true`, the exception is swallowed and not transitioned to JNI.
Refactor `AndroidEnvironment.UnhandledException()` to extract the
event- raising logic into `TryRaiseUnhandledException()` so it can be
called from both the old and new code paths.
~~ Tests ~~
Add a test that verifies both `UnhandledExceptionRaiser` and
`AppDomain.UnhandledException` fire when an unhandled exception is
thrown from a button click handler.
The test:
1. Registers both `UnhandledExceptionRaiser` (with `e.Handled = true`)
and `AppDomain.UnhandledException` handlers
2. Throws from the button click delegate
3. Asserts `UnhandledExceptionRaiser` fires via logcat1 parent 24d6a92 commit 2ccdb27
File tree
3 files changed
+59
-4
lines changed- src/Mono.Android/Android.Runtime
- tests/MSBuildDeviceIntegration/Tests
3 files changed
+59
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
115 | 124 | | |
116 | 125 | | |
117 | 126 | | |
118 | 127 | | |
119 | 128 | | |
120 | | - | |
| 129 | + | |
121 | 130 | | |
122 | 131 | | |
123 | | - | |
124 | | - | |
| 132 | + | |
125 | 133 | | |
126 | 134 | | |
127 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
76 | 89 | | |
77 | 90 | | |
78 | 91 | | |
| |||
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
530 | 530 | | |
531 | 531 | | |
532 | 532 | | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
533 | 567 | | |
534 | 568 | | |
535 | 569 | | |
| |||
0 commit comments