Error when using await in override void onAppearing

Daniel Desire 21 Reputation points

Hi Team,

I'm actually moving my app from xamarin to .net maui.

In one of my app page. An alert is displayed when the screen is loaded.

Using the protected override void OnAppearing().

But when I do the same in .net maui, the app crash before the page is loaded.

If I removed the await DisplayAlert part, the page is loaded correctly.

Below sample code:

protected override async void OnAppearing()

            NetworkAccess accessType = Connectivity.Current.NetworkAccess;

            if (accessType == NetworkAccess.Internet)
                bool answer = await DisplayAlert("Connectivity Info", "You do not have internet connection" + "\n" + "Show your Offline Card??", "Yes", "No");

                if (answer == true)
                    await Shell.Current.GoToAsync(state: "OfflineCard");
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,840 questions
{count} votes