Error when using await in override void onAppearing

Daniel Desire 21 Reputation points
2023-01-17T10:10:28.53+00:00

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()
        {
            base.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");
                }
            }
        }
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,868 questions
{count} votes