Xamarin.forms: Setting Main Page in quick succession causes crash on Android

Created on 8 Dec 2017  路  5Comments  路  Source: xamarin/Xamarin.Forms

Description

When setting the main page of an application twice in quick succession, the app crashes with an IllegalArgumentException on Android.

Steps to Reproduce

  1. Set the main page of an application to a NavigationPage
  2. A short time after, set the main page again

Expected Behavior

The application navigates to the first page, then the second.

Actual Behavior

The application crashes.

Basic Information

  • Version with issue: 2.5
  • Visual Studio Version: VS for Mac 7.3

  • Platform Target Frameworks:

    • Android: 7.1
  • Android Support Library Version: 25.4.0.2

Below is a stack trace from the attached sample application:
--- End of managed Java.Lang.IllegalArgumentException stack trace ---
java.lang.IllegalArgumentException: No view found for id 0x3 (unknown) for fragment FragmentContainer{eabbdaa #0 id=0x3}
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1334)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1569)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1636)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2415)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2201)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2155)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2064)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:718)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

Here is another stacktrace from our application in development, which seems to point to the disposal of the NavigationPageRenderer.

java.lang.IllegalArgumentException: No view found for id 0x2 (unknown) for fragment FragmentContainer{1b3651a #0 id=0x2}
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1293
android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState()FragmentManager.java:1528
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1595
android.support.v4.app.BackStackRecord.executeOps()BackStackRecord.java:758
android.support.v4.app.FragmentManagerImpl.executeOps()FragmentManager.java:2363
android.support.v4.app.FragmentManagerImpl.executeOpsTogether()FragmentManager.java:2149
android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps()FragmentManager.java:2103
android.support.v4.app.FragmentManagerImpl.execPendingActions()FragmentManager.java:2013
android.support.v4.app.FragmentManagerImpl.executePendingTransactions()FragmentManager.java:763
mono.java.lang.RunnableImplementor.n_run(Native Method)
mono.java.lang.RunnableImplementor.run()RunnableImplementor.java:30
android.os.Handler.handleCallback()Handler.java:751
android.os.Handler.dispatchMessage()Handler.java:95
android.os.Looper.loop()Looper.java:154
android.app.ActivityThread.main()ActivityThread.java:6077
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:865
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:755
caused.RuntimeException(unknown)
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()<01e1b59e4261433ba399257491230b03>:0
Java.Interop.JniEnvironment.InstanceMethods.CallBooleanMethod(JniObjectReference instance, JniMethodInfo method)<02d99c7710584bb18b40b9052f4c0bab>:0
Android.Runtime.JNIEnv.CallBooleanMethod(IntPtr jobject, IntPtr jmethod)<27f5f7ad675348b8b88d2eb52bf5ff31>:0
Android.Support.V4.App.FragmentManagerInvoker.ExecutePendingTransactions()<7e083afc7c9045f59e01d9c14931060d>:0
Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.Dispose(bool disposing)<1481f85a917c4f2b882ea161e9bc082f>:0
Java.Lang.Object.Dispose()<27f5f7ad675348b8b88d2eb52bf5ff31>:0
Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage(Page newRoot)<1481f85a917c4f2b882ea161e9bc082f>:0
Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage(Page page)<1481f85a917c4f2b882ea161e9bc082f>:0
Xamarin.Forms.Platform.Android.FormsAppCompatActivity.AppOnPropertyChanged(object sender, PropertyChangedEventArgs args)<1481f85a917c4f2b882ea161e9bc082f>:0
Xamarin.Forms.BindableObject.OnPropertyChanged(string propertyName)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Element.OnPropertyChanged(string propertyName)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Application.set_MainPage(Page value)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Company.Forms.Services.NavigationService.<>c__DisplayClass11_0.<b__0>d.MoveNext()<093836f8b263470cbe4aa7ecb3e2d09b>:0
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()<01e1b59e4261433ba399257491230b03>:0
System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.b__6_0(object state)<01e1b59e4261433ba399257491230b03>:0
Android.App.SyncContext.<>c__DisplayClass2_0.b__0()<27f5f7ad675348b8b88d2eb52bf5ff31>:0
Java.Lang.Thread.RunnableImplementor.Run()<27f5f7ad675348b8b88d2eb52bf5ff31>:0
Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this)<27f5f7ad675348b8b88d2eb52bf5ff31>:0
at (wrapper dynamic-method) System.Object:f04862c3-b38a-42d2-895a-840077e201b6 (intptr,intptr)
--- End of managed Java.Lang.RuntimeException stack trace ---
java.lang.IllegalArgumentException: No view found for id 0x2 (unknown) for fragment FragmentContainer{1b3651a #0 id=0x2}
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1293
android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState()FragmentManager.java:1528
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1595
android.support.v4.app.BackStackRecord.executeOps()BackStackRecord.java:758
android.support.v4.app.FragmentManagerImpl.executeOps()FragmentManager.java:2363
android.support.v4.app.FragmentManagerImpl.executeOpsTogether()FragmentManager.java:2149
android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps()FragmentManager.java:2103
android.support.v4.app.FragmentManagerImpl.execPendingActions()FragmentManager.java:2013
android.support.v4.app.FragmentManagerImpl.executePendingTransactions()FragmentManager.java:763
mono.java.lang.RunnableImplementor.n_run(Native Method)
mono.java.lang.RunnableImplementor.run()RunnableImplementor.java:30
android.os.Handler.handleCallback()Handler.java:751
android.os.Handler.dispatchMessage()Handler.java:95
android.os.Looper.loop()Looper.java:154
android.app.ActivityThread.main()ActivityThread.java:6077
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:865
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:755

Reproduction Link

navigationcrash.zip

Android bug

Most helpful comment

It's been confirmed and it's in the queue to be worked on, but no progress just yet.

All 5 comments

@jassmith @hartez Any news about this?

It's been confirmed and it's in the queue to be worked on, but no progress just yet.

I've the same issue when app is from background, i've set the start point of the app again and crash, any news about this?

Any solution?

@sohitEngg This is fixed in version 2.5.1 and up.

Was this page helpful?
0 / 5 - 0 ratings