Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DisplayAlert causing application to crash in Xamarin.Forms

When ever I try to put an alert message on any page in my application, the application crashes just before displaying the alert in Xamarin.Forms.

async void OnAlertYesNoClicked (object sender, EventArgs e)
{
  var answer = await DisplayAlert ("Question?", "Would you like to play a game", "Yes", "No");

}

Can somebody please suggest how to fix this issue?

like image 572
A. Sinha Avatar asked Dec 06 '25 07:12

A. Sinha


1 Answers

Can you check to see that it's initialized? Also check the thread that is calling DisplayAlert to make sure it's the main thread. And just to be safe, are you able to change the async void to async Task?

like image 65
joe Avatar answered Dec 08 '25 13:12

joe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!