-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when using DisplayAlert in override void onAppearing #12739
Comments
Link to public reproduction project repository |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
Some potentially useful information; (I was able to run your project and encounter the same issue with DisplayAlert)
The stack trace is a bit different in visual studio when it traps it
I suspect the splash screen is still disposing at the time the main screen is showing or just something in general isn't ready for the kind of interaction you're asking for, so on a hunch I tried adding a delay before doing the Display Alert thing, and then the popup showed. This works. But, this isn't a viable solution or workaround, but it may help the team with debugging or understanding where the problem is: public async Task CheckInternetConnectivity()
{
NetworkAccess accessType = Connectivity.Current.NetworkAccess;
if (accessType == NetworkAccess.Internet)
{
await MainThread.InvokeOnMainThreadAsync(async () =>
{
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");
}
});
}
}
protected override void OnAppearing()
{
base.OnAppearing();
Task.Run(async () => { await Task.Delay(5000); await CheckInternetConnectivity(); }) ;
} |
Hi Shadow, thanks for the work around. I will try it and keep you posted. |
Could be fixed by #12910 |
I had the same Problem and use then the event Loaded on the first StackLayout, then the DisplayAlert works.
|
Hi Team, Thanks @jsuarezruiz for the info. I have tested it and it is now working correctly. Closing the ticket. |
I am not so sure this is fixed. I had the exact same problem with DisplayAlert during OnAppearing and adding the delay before it fixed the problem. I only noticed this happening on Windows but the fix applies to all 4 platforms. |
Hello lovely human, thank you for your comment on this issue. Because this issue has been closed for a period of time, please strongly consider opening a new issue linking to this issue instead to ensure better visibility of your comment. Thank you! |
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();
Steps to Reproduce
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
The text was updated successfully, but these errors were encountered: