Closed JDanBankai closed 1 year ago
Link to public reproduction project repository https://github.com/JDanBankai/DisplayAlertError
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)
Time Device Name Type PID Tag Message
01-23 11:06:28.122 Datalogic Memor K Warning 698 System.err java.lang.Throwable
at com.mediatek.server.wifi.MtkWifiService$AutoConnectManager.setDisconnectOperation(MtkWifiService.java:340)
at com.mediatek.server.wifi.MtkWifiService$AutoConnectManager.access$300(MtkWifiService.java:206)
at com.mediatek.server.wifi.MtkWifiService$MtkWifiOpReceiver.onReceive(MtkWifiService.java:170)
at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1432)
at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at com.android.server.SystemServer.run(SystemServer.java:502)
at com.android.server.SystemServer.main(SystemServer.java:329)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:891)
The stack trace is a bit different in visual studio when it traps it
System.Reflection.TargetInvocationException
0xFFFFFFFFFFFFFFFF in Android.Runtime.JNIEnv.monodroid_debugger_unhandled_exception C#
0x1A in Android.Runtime.JNINativeWrapper._unhandled_exception at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:12,5 C#
0x23 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:353,26 C#
0x32 in System.Reflection.MethodInvoker.InterpretedInvoke C#
0x4 in System.Reflection.MethodInvoker.InlinedInvoke C#
0xCE in System.Reflection.RuntimeMethodInfo.Invoke C#
0x6 in System.Reflection.MethodBase.Invoke C#
0x95 in Microsoft.Maui.Controls.MessagingCenter.Subscription.InvokeCallback at D:\a\_work\1\s\src\Controls\src\Core\MessagingCenter.cs:97,5 C#
0x70 in Microsoft.Maui.Controls.MessagingCenter.InnerSend at D:\a\_work\1\s\src\Controls\src\Core\MessagingCenter.cs:220,6 C#
0x35 in Microsoft.Maui.Controls.MessagingCenter.Microsoft.Maui.Controls.IMessagingCenter.Send<Microsoft.Maui.Controls.Page, Microsoft.Maui.Controls.Internals.AlertArguments> at D:\a\_work\1\s\src\Controls\src\Core\MessagingCenter.cs:118,4 C#
0x8 in Microsoft.Maui.Controls.MessagingCenter.Send<Microsoft.Maui.Controls.Page, Microsoft.Maui.Controls.Internals.AlertArguments> at D:\a\_work\1\s\src\Controls\src\Core\MessagingCenter.cs:111,4 C#
0x11 in Microsoft.Maui.Controls.Page. at D:\a\_work\1\s\src\Controls\src\Core\Page.cs:242,31 C#
0x33 in Microsoft.Maui.Controls.Page.FlushPendingActions at D:\a\_work\1\s\src\Controls\src\Core\Page.cs:270,6 C#
0x15 in Microsoft.Maui.Controls.Page.SendNavigatedTo at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\Page.Impl.cs:46,4 C#
0x6C in Microsoft.Maui.Controls.Shell.SendNavigated at D:\a\_work\1\s\src\Controls\src\Core\Shell\Shell.cs:1166,4 C#
0x2 in Microsoft.Maui.Controls.Shell.<.ctor>b__172_0 at D:\a\_work\1\s\src\Controls\src\Core\Shell\Shell.cs:803,49 C#
0x1D in Microsoft.Maui.Controls.ShellNavigationManager. at D:\a\_work\1\s\src\Controls\src\Core\Shell\ShellNavigationManager.cs:274,6 C#
0x12 in Microsoft.Maui.Controls.ShellNavigationManager. at D:\a\_work\1\s\src\Controls\src\Core\Shell\ShellNavigationManager.cs:264,7 C#
0x22 in Microsoft.Maui.Controls.BaseShellItem.OnAppearing at D:\a\_work\1\s\src\Controls\src\Core\Shell\BaseShellItem.cs:168,5 C#
0x136 in Microsoft.Maui.Controls.ShellNavigationManager.HandleNavigated at D:\a\_work\1\s\src\Controls\src\Core\Shell\ShellNavigationManager.cs:262,6 C#
0x6D in Microsoft.Maui.Controls.ShellNavigationManager. at D:\a\_work\1\s\src\Controls\src\Core\Shell\ShellNavigationManager.cs:243,7 C#
0x65 in Microsoft.Maui.Controls.Element.OnChildAdded at D:\a\_work\1\s\src\Controls\src\Core\Element.cs:357,3 C#
0x2 in Microsoft.Maui.Controls.ShellContent.OnChildAdded at D:\a\_work\1\s\src\Controls\src\Core\Shell\ShellContent.cs:153,4 C#
0x28 in Microsoft.Maui.Controls.BaseShellItem.AddLogicalChild at D:\a\_work\1\s\src\Controls\src\Core\Shell\BaseShellItem.cs:274,4 C#
0x30 in Microsoft.Maui.Controls.ShellContent.set_ContentCache at D:\a\_work\1\s\src\Controls\src\Core\Shell\ShellContent.cs:192,6 C#
0x84 in Microsoft.Maui.Controls.ShellContent.Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent at D:\a\_work\1\s\src\Controls\src\Core\Shell\ShellContent.cs:81,5 C#
0x16E in Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.OnCreateView at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellSectionRenderer.cs:123,5 C#
0x24 in AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ at /Users/runner/work/1/s/generated/androidx.fragment.fragment/obj/Release/net6.0-android/generated/src/AndroidX.Fragment.App.Fragment.cs:2031,4 C#
0xD in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:352,5 C#
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 https://github.com/dotnet/maui/pull/12910
Is already working on main branch
I had the same Problem and use then the event Loaded on the first StackLayout, then the DisplayAlert works.
<StackLayout
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Style="{StaticResource BackgroundStyle}"
Loaded="StackLayout_Loaded"
>
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