Skip to content

Error when using DisplayAlert in override void onAppearing #12739

@JDanBankai

Description

@JDanBankai

Description

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:

ASP.NET (C#)

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");
            }
        }
    }

Steps to Reproduce

  1. Create a File > New .NET MAUI App
  2. Override the OnAppearing
  3. Add a DisplayAlert after base.OnAppearing();

Expected outcome: An alert is display when the page is loaded.
Actual outcome: the app crash before the page is loaded.

Link to public reproduction project repository

https://github.com/dotnet/maui/blob/main/.github/repro.md

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows, macOS

Affected platform versions

All

Did you find any workaround?

No

Relevant log output

'MauiApp3.exe' (CoreCLR: DefaultDomain): Loaded 'C:\Users\DDESIRE\source\repos\MauiApp3\MauiApp3\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\AppX\System.Private.CoreLib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MauiApp3.exe' (CoreCLR: clrhost): Loaded 'C:\Users\DDESIRE\source\repos\MauiApp3\MauiApp3\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\AppX\MauiApp3.dll'. Symbols loaded.
'MauiApp3.exe' (CoreCLR: clrhost): Loaded 'C:\Users\DDESIRE\source\repos\MauiApp3\MauiApp3\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\AppX\System.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MauiApp3.exe' (CoreCLR: clrhost): Loaded 'C:\Users\DDESIRE\source\repos\MauiApp3\MauiApp3\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\AppX\Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MauiApp3.exe' (CoreCLR: clrhost): Loaded 'C:\Users\DDESIRE\source\repos\MauiApp3\MauiApp3\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\AppX\System.Runtime.InteropServices.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MauiApp3.exe' (CoreCLR: clrhost): Loaded 'C:\Users\DDESIRE\source\repos\MauiApp3\MauiApp3\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\AppX\WinRT.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MauiApp3.exe' (CoreCLR: clrhost): Loaded 'C:\Users\DDESIRE\source\repos\MauiApp3\MauiApp3\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\AppX\System.Collections.Concurrent.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MauiApp3.exe' (CoreCLR: clrhost): Loaded 'C:\Users\DDESIRE\source\repos\MauiApp3\MauiApp3\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\AppX\System.Collections.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MauiApp3.exe' (CoreCLR: clrhost): Loaded 'C:\Users\DDESIRE\source\repos\MauiApp3\MauiApp3\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\AppX\System.Threading.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MauiApp3.exe' (CoreCLR: clrhost): Loaded 'C:\Users\DDESIRE\source\repos\MauiApp3\MauiApp3\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\AppX\System.Runtime.CompilerServices.Unsafe.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MauiApp3.exe' (CoreCLR: clrhost): Loaded 'C:\Users\DDESIRE\source\repos\MauiApp3\MauiApp3\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\AppX\System.Private.Uri.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MauiApp3.exe' (CoreCLR: clrhost): Loaded 'C:\Users\DDESIRE\source\repos\MauiApp3\MauiApp3\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\AppX\System.ObjectModel.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MauiApp3.exe' (CoreCLR: clrhost): Loaded 'C:\Users\DDESIRE\source\repos\MauiApp3\MauiApp3\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\AppX\System.ComponentModel.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MauiApp3.exe' (CoreCLR: clrhost): Loaded 'C:\Users\DDESIRE\source\repos\MauiApp3\MauiApp3\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\AppX\System.Numerics.Vectors.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[21732] MauiApp3.exe' has exited with code 2147942405 (0x80070005).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-dialogalertDisplayAlert, dialogmigration-compatibilityXamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convertp/1Work that is important, and has been scheduled for release in this or an upcoming sprintpartner/cat 😻this is an issue that impacts one of our partners or a customer our advisory team is engaged withplatform/androidplatform/iosplatform/macosmacOS / Mac Catalystplatform/windowst/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions