Skip to content
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

.NET MAUI - Redirecting to AppShell page throws "Can not perform this action after onsaveinstancestate" exception #18159

Closed
DharunAR opened this issue Oct 19, 2023 · 8 comments
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout area-navigation NavigationPage migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 s/triaged Issue has been reviewed t/bug Something isn't working
Milestone

Comments

@DharunAR
Copy link

Description

I am in the progress on migrating my Xamarin project to MAUI with .NET 7.

I have a login page when the app opens, on button click the login process will happen via WebAuthenticator. Once the login is successful I am redirecting to AppShell Page.

On redirecting to appshell, I am getting error ""

Steps to Reproduce

  1. Clone the reproduction project repository to your local.
  2. I have added my mobileAPP microsoft login URL in webAuthenticator, you can use any URL which can redirect back to the APP.
  3. On redirecting to AppShell page, you can find it throws the error.
  4. I am calling AppShell page on "Onresume" method.

image

Link to public reproduction project repository

https://github.com/DharunAR/SecureTest

Version with bug

7.0.96

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 12 and 13.

Did you find any workaround?

No.

Relevant log output

No response

@DharunAR DharunAR added the t/bug Something isn't working label Oct 19, 2023
@jsuarezruiz jsuarezruiz added area-navigation NavigationPage area-controls-shell Shell Navigation, Routes, Tabs, Flyout platform/android 🤖 labels Oct 19, 2023
@mattleibow mattleibow added this to the Backlog milestone Oct 19, 2023
@ghost
Copy link

ghost commented Oct 19, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@DharunAR
Copy link
Author

DharunAR commented Oct 20, 2023

Since it is been added to the Backlog. Do we have any workaround for this issue? This is blocking us from our migration.

@samhouts samhouts added the migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert label Oct 20, 2023
@Gekidoku
Copy link

Gekidoku commented Oct 26, 2023

I found that doing the change on the mainthread and adding a delay works. on faster phones.
some customers of mine still have this crash on something like a samsung xcover 4 or 5

MainThread.BeginInvokeOnMainThread(async () =>
{
            
           await Task.Delay(100);
               MainPage = new AppShell();
            });
});

@damiand2
Copy link

damiand2 commented Nov 15, 2023

Same issue here - setting MainPage to AppShell causes random crashes on production with callstack like:
Java.Interop.JniEnvironment.InstanceMethods.CallIntMethod(JniObjectReference , JniMethodInfo , JniArgumentValue* ) Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeAbstractInt32Method(String , IJavaPeerable , JniArgumentValue* ) AndroidX.Fragment.App.FragmentTransactionInvoker.Commit() Microsoft.Maui.Platform.NavigationRootManager.SetContentView(IView view) Microsoft.Maui.Platform.NavigationRootManager.Connect(IView view, IMauiContext mauiContext) Microsoft.Maui.Handlers.WindowHandler.CreateRootViewFromContent(IWindowHandler handler, IWindow window) Microsoft.Maui.Handlers.WindowHandler.MapContent(IWindowHandler handler, IWindow window) Microsoft.Maui.PropertyMapper``2.<>c__DisplayClass5_0[[Microsoft.Maui.IWindow, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IWindowHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v) Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) Microsoft.Maui.PropertyMapper.UpdateProperty(IElementHandler viewHandler, IElement virtualView, String property) Microsoft.Maui.Handlers.ElementHandler.UpdateValue(String property) Microsoft.Maui.Controls.Window.OnPropertyChanged(String propertyName) Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value, Boolean fromStyle, Boolean checkAccess) Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value) Microsoft.Maui.Controls.Window.set_Page(Page value) Microsoft.Maui.Controls.Application.set_MainPage(Page value) XXX.Mobile.App.<InitializeUI>b__2_5() Java.Lang.Thread.RunnableImplementor.Run() Java.Lang.IRunnableInvoker.n_Run(IntPtr , IntPtr ) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V , IntPtr , IntPtr ) java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState androidx.fragment.app.FragmentManager.checkStateLoss FragmentManager.java:1632 androidx.fragment.app.FragmentManager.enqueueAction FragmentManager.java:1672 androidx.fragment.app.BackStackRecord.commitInternal BackStackRecord.java:341 androidx.fragment.app.BackStackRecord.commit BackStackRecord.java:306 mono.java.lang.RunnableImplementor.n_run(Native Method) mono.java.lang.RunnableImplementor.run RunnableImplementor.java:31 android.os.Handler.handleCallback Handler.java:938 android.os.Handler.dispatchMessage Handler.java:99 android.os.Looper.loopOnce Looper.java:226 android.os.Looper.loop Looper.java:313 android.app.ActivityThread.main ActivityThread.java:8669 java.lang.reflect.Method.invoke(Native Method) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:571 com.android.internal.os.ZygoteInit.main ZygoteInit.java:1135

@Gekidoku
Copy link

Seems the sleep doesnt always work. still getting the error in google play crash logs.

@pulmuone
Copy link

pulmuone commented Jan 9, 2024

Same issue here - setting MainPage to AppShell causes random crashes on production with callstack like: Java.Interop.JniEnvironment.InstanceMethods.CallIntMethod(JniObjectReference , JniMethodInfo , JniArgumentValue* ) Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeAbstractInt32Method(String , IJavaPeerable , JniArgumentValue* ) AndroidX.Fragment.App.FragmentTransactionInvoker.Commit() Microsoft.Maui.Platform.NavigationRootManager.SetContentView(IView view) Microsoft.Maui.Platform.NavigationRootManager.Connect(IView view, IMauiContext mauiContext) Microsoft.Maui.Handlers.WindowHandler.CreateRootViewFromContent(IWindowHandler handler, IWindow window) Microsoft.Maui.Handlers.WindowHandler.MapContent(IWindowHandler handler, IWindow window) Microsoft.Maui.PropertyMapper2.<>c__DisplayClass5_0[[Microsoft.Maui.IWindow, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IWindowHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].b__0(IElementHandler h, IElement v) Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) Microsoft.Maui.PropertyMapper.UpdateProperty(IElementHandler viewHandler, IElement virtualView, String property) Microsoft.Maui.Handlers.ElementHandler.UpdateValue(String property) Microsoft.Maui.Controls.Window.OnPropertyChanged(String propertyName) Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value, Boolean fromStyle, Boolean checkAccess) Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value) Microsoft.Maui.Controls.Window.set_Page(Page value) Microsoft.Maui.Controls.Application.set_MainPage(Page value) XXX.Mobile.App.b__2_5() Java.Lang.Thread.RunnableImplementor.Run() Java.Lang.IRunnableInvoker.n_Run(IntPtr , IntPtr ) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V , IntPtr , IntPtr ) java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState androidx.fragment.app.FragmentManager.checkStateLoss FragmentManager.java:1632 androidx.fragment.app.FragmentManager.enqueueAction FragmentManager.java:1672 androidx.fragment.app.BackStackRecord.commitInternal BackStackRecord.java:341 androidx.fragment.app.BackStackRecord.commit BackStackRecord.java:306 mono.java.lang.RunnableImplementor.n_run(Native Method) mono.java.lang.RunnableImplementor.run RunnableImplementor.java:31 android.os.Handler.handleCallback Handler.java:938 android.os.Handler.dispatchMessage Handler.java:99 android.os.Looper.loopOnce Looper.java:226 android.os.Looper.loop Looper.java:313 android.app.ActivityThread.main ActivityThread.java:8669 java.lang.reflect.Method.invoke(Native Method) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:571 com.android.internal.os.ZygoteInit.main ZygoteInit.java:1135 ``

Same Issue

@PureWeen
Copy link
Member

PureWeen commented Jan 9, 2024

Duplicate of #11501

Try doing it inside OnActivated instead of OnResume

@PureWeen PureWeen closed this as completed Jan 9, 2024
@pulmuone
Copy link

Duplicate of #11501

Try doing it inside OnActivated instead of OnResume

The app is crashing randomly.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout area-navigation NavigationPage migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants