-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Description
Calling DisplayAlertAsync for an unloaded page results in a NullReferenceException. I would instead expect either that the call is ignored, or the alert is displayed.
Stack trace:
12-24 15:45:30.929 E/AndroidRuntime( 7793): FATAL EXCEPTION: main
12-24 15:45:30.929 E/AndroidRuntime( 7793): Process: com.companyname.displayalertasynccrashrepro, PID: 7793
12-24 15:45:30.929 E/AndroidRuntime( 7793): android.runtime.JavaProxyThrowable: [System.NullReferenceException]: Object reference not set to an instance of an object.
12-24 15:45:30.929 E/AndroidRuntime( 7793): at Microsoft.Maui.Controls.Page.DisplayAlertAsync(//src/Controls/src/Core/Page/Page.cs:388)
12-24 15:45:30.929 E/AndroidRuntime( 7793): at Microsoft.Maui.Controls.Page.DisplayAlertAsync(//src/Controls/src/Core/Page/Page.cs:357)
12-24 15:45:30.929 E/AndroidRuntime( 7793): at DisplayAlertAsyncCrashRepro.SecondPage+d__1.MoveNext(C:\Operations\Build\Home\repros\DisplayAlertAsyncCrashRepro\DisplayAlertAsyncCrashRepro\SecondPage.xaml.cs:16)
12-24 15:45:30.929 E/AndroidRuntime( 7793): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw + 0x11(Unknown Source)
12-24 15:45:30.929 E/AndroidRuntime( 7793): at System.Threading.Tasks.Task+<>c.b__124_0 + 0x0(Unknown Source)
12-24 15:45:30.929 E/AndroidRuntime( 7793): at Android.App.SyncContext+<>c__DisplayClass2_0.b__0 + 0x0(Unknown Source)
12-24 15:45:30.929 E/AndroidRuntime( 7793): at Java.Lang.Thread+RunnableImplementor.Run + 0x8(Unknown Source)
Steps to Reproduce
- Run the repro
- Click on the button
- When the second page appears, click on the button again
- Observe the exception be thrown in a few seconds
Link to public reproduction project repository
https://github.com/mfeingol/repros/tree/main/DisplayAlertAsyncCrashRepro
Version with bug
10.0.20
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Tested on Android API 36.1, but seems to repro in general
Did you find any workaround?
The code can check whether the page's IsLoaded property is enabled before calling DisplayAlertAsync. But nobody's code does that.