Xamarin.forms: [Bug] [iOS] [Shell] "Nav Stack consistency error"

Created on 12 Nov 2019  路  22Comments  路  Source: xamarin/Xamarin.Forms

Description

I am getting an exception report in AppCenter, _"Nav Stack consistency error"_. Occurring in all versions of XForms (including nightly, was hoping #8135 might have helped but no effect).

Multiple versions of iOS (13, 12 & 11), affecting about ~5% of users. I have not been able to replicate and have no way to reach out to users to get retry steps.

IShellSectionController.SendPopping (Xamarin.Forms.Page page)
ShellSectionRenderer.SendPoppedOnCompletion (System.Threading.Tasks.Task popTask)
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state)
NSAsyncSynchronizationContextDispatcher.Apply ()
(wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)
UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)
Application.Main (System.String[] args)

Steps to Reproduce

I have a TabBar setup in my AppShell. Three tabs with only a single content page as the child. In the Shell's constructor I also register some modal routes, which I navigate to using Shell.GoToAsync(). I do not trigger navigation in any other way, nor do I pop anything off the stack manually.

Expected Behavior

Obviously I could be at fault here, but it would be helpful if the exception contained some more information to aid in debugging. Possibly the name of the page it's trying to pop (when available) and the current state of the navigation stack.

Actual Behavior

Generic exception, which is difficult to debug/troubleshoot.

Basic Information

  • Version with issue: All (including nightly)
shell 6 in-progress bug

Most helpful comment

I've got the same exception in my app when user starts a "back" swipe from a page, but do not complete the movement.

I don't know how to solve it since I have no control on such navigation (or at least it is what I think...)

All 22 comments

I got one too yesterday while debugging my app. I think it happened after changing the orientation of my device to landscape and back to portrait, but I haven't been able to reproduce it.

At least it's not just me 馃槉. My app is portrait only (no rotation enabled).

Same issue for me in an unpredictable way, but when it occours is during Popping to AppShell (Tabbed Page) event, from a page where Shell.TabBarIsVisible="False"

I have the same issue, 100 % reproduceable with following stacktrace.
My setup is following:
Shell with many ShellItems, each with only 1 childView
User takes a picture ->
opens a custom CameraView takes picture (modal push)
opens Custom Displayview (another modal push)
closes both pages ( 2x popasync)
crashes with exception.

I have to put a small delay between the popasyncs (200 ms) or the app will also crash #6484

System.Exception: Nav Stack consistency error
at Xamarin.Forms.ShellSection.Xamarin.Forms.IShellSectionController.SendPopping (Xamarin.Forms.Page page) [0x0000e] in D:\a1\s\Xamarin.Forms.Core\Shell\ShellSection.cs:137
at Xamarin.Forms.Platform.iOS.ShellSectionRenderer.SendPoppedOnCompletion (System.Threading.Tasks.Task popTask) [0x0004f] in D:\a1\s\Xamarin.Forms.Platform.iOS\Renderers\ShellSectionRenderer.cs:404
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) [0x00000] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.6.0.12/src/Xamarin.iOS/Foundation/NSAction.cs:178
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.6.0.12/src/Xamarin.iOS/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.6.0.12/src/Xamarin.iOS/UIKit/UIApplication.cs:65

I've got the same exception in my app when user starts a "back" swipe from a page, but do not complete the movement.

I don't know how to solve it since I have no control on such navigation (or at least it is what I think...)

I am having the same problem now. I anyone looking at this? My app keeps crashing.

Is anyone able to create a small reproducible example?

In theory, a possible fix would be changing,

void IShellSectionController.SendPopping(Page page)
{
    if (_navStack.Count <= 1)
        throw new Exception("Nav Stack consistency error");

    _navStack.Remove(page);
    SendAppearanceChanged();
}

to,

void IShellSectionController.SendPopping(Page page)
{
    if (_navStack.Contains(page))
        _navStack.Remove(page);

        SendAppearanceChanged();            
}

But without something reproducible it's a stab in the dark and could cause its own issues.

I get this same issue when I try to swipe back from a detail page but stop in the middle of the swipe then I press the back button. It works fine on XF4.2.0.70949 but does not work on XF4.3.0.991221. I have not tried any other versions.

I have attached two GIFs. One with it working and another with it crashing.

Working
XF_4_2_0_70949_working

Crashing
XF4_3_0_991221_Crash

Thanks @TimBarham!

Looks like PopViewController is called on the start of the back swipe gesture, even if it is cancelled. This removes the page from the Shell's navigation stack, but it still exists for the UINavigationController.

I get this same issue when I try to swipe back from a detail page but stop in the middle of the swipe then I press the back button. It works fine on XF4.2.0.70949 but does not work on XF4.3.0.991221. I have not tried any other versions.

This is exactly the same problem with my app.

Anyone looking into this / any update on progress?

Xamarin.Forms.ShellSection.Xamarin.Forms
IShellSectionController.SendPopping (Xamarin.Forms.Page page)
Xamarin.Forms.Platform.iOS
ShellSectionRenderer.SendPoppedOnCompletion (System.Threading.Tasks.Task popTask)
System.Runtime.CompilerServices
AsyncMethodBuilderCore+<>c.b__7_0 (System.Object )

Hi, Even I am getting errors similar to the above mentioned comments.
Can you please look into the entire Navigation of Xamarin Forms Shell .

@rscholey @nikhildpardasani

There is a PR (#8875) for this issue. Hopefully it will be resolved soon.

I'm using a custom Shell renderer to disable the swipe gesture as a workaround (sample gist).

Can you please check out issue: https://github.com/xamarin/Xamarin.Forms/issues/9006 as maybe they are related.

In my case it seems that XF is incorrectly calculating a route but I'm only seeing this on iOS and not Android:

{
"length": 0,
"offset": 0,
"id": "22663f70-9102-4c60-ad2d-a518e76c80da",
"exception": {
"type": "System.ArgumentException",
"message": "unable to figure out route for: //TabBar12/Tab5/DictionaryTab/DictionaryTab/CardListPage/DictionaryTab/CardListPage\nParameter name: uri",
"stackTrace": " at Xamarin.Forms.ShellUriHandler.GetNavigationRequest (Xamarin.Forms.Shell shell, System.Uri uri, System.Boolean enableRelativeShellRoutes) <0x105127e00 + 0x00398> in :0 \n at Xamarin.Forms.Shell.GoToAsync (Xamarin.Forms.ShellNavigationState state, System.Boolean animate, System.Boolean enableRelativeShellRoutes) <0x105119bd0 + 0x000d7> in :0 \n at Japanese.Helper.OpenPageAsync (System.String route) <0x105ccf3a0 + 0x00197> in <460a5aefe005480680b03f394d540b43#b033c4571e79ba3dba4f10c91e4b8190>:0 ",
"wrapperSdkName": "appcenter.xamarin"
},
"properties": {
"exception": "System.ArgumentException: unable to figure out route for: //TabBar12/Tab5/DictionaryTab/DictionaryTab/CardListPage/Dictionary",
"device Model": "iPhone8,1",
"helper": "OpenPageAsync",
"route": "//TabBar12/Tab5/DictionaryTab/DictionaryTab/CardListPage/DictionaryTab/CardListPage"
},
"appId": "cb7fb1ab-8e1b-4344-9094-17b6c4c95fe4",
"installId": "31C8C4DD-189D-4312-BB46-CC4BD17281CC",
"isTestMessage": false,
"timestamp": "2019-12-22T21:32:05.429Z",
"sid": "7a05f33f-8048-4dbd-9c58-03ef6d99d308",
"device": {
"sdkName": "appcenter.ios",
"sdkVersion": "2.5.1",
"wrapperSdkVersion": "2.6.2",
"wrapperSdkName": "appcenter.xamarin",
"model": "iPhone8,1",
"oemName": "Apple",
"osName": "iOS",
"osVersion": "13.1.3",
"osBuild": "17A878",
"locale": "fr_FR",
"timeZoneOffset": 60,
"screenSize": "1334x750",
"appVersion": "0.4.1",
"carrierName": "Orange France",
"carrierCountry": "fr",
"appBuild": "0.4.1",
"appNamespace": "com.ankiplus.Japanese",
"wrapperRuntimeVersion": "12.6.0"
}
}

@rscholey Unfortunately, I don't think this is related. This issue is specifically regarding a crash when dismissing pages using a swipe gesture.

Thanks dmariogatto.

However this is still an issue related to the nav stack and I hope someone can look into how the nav stack can generate a route like this with repeated values of "HelpTab" spread through the route :-(

{
"length": 0,
"offset": 0,
"id": "d6e63703-1c72-4e9b-bfb6-c0396f545afa",
"exception": {
"type": "System.ArgumentException",
"message": "unable to figure out route for: //TabBar12/Tab9/HelpTab/HelpTab/IntroductionPage/HelpTab/Concept\nParameter name: uri",
"stackTrace": " at Xamarin.Forms.ShellUriHandler.GetNavigationRequest (Xamarin.Forms.Shell shell, System.Uri uri, System.Boolean enableRelativeShellRoutes) <0x100a1fe00 + 0x00398> in :0 \n at Xamarin.Forms.Shell.GoToAsync (Xamarin.Forms.ShellNavigationState state, System.Boolean animate, System.Boolean enableRelativeShellRoutes) <0x100a11bd0 + 0x000d7> in :0 \n at Japanese.Helper.OpenPageAsync (System.String route) <0x1015c73a0 + 0x00197> in <460a5aefe005480680b03f394d540b43#b033c4571e79ba3dba4f10c91e4b8190>:0 ",
"wrapperSdkName": "appcenter.xamarin"
},
"properties": {
"exception": "System.ArgumentException: unable to figure out route for: //TabBar12/Tab9/HelpTab/HelpTab/IntroductionPage/HelpTab/Concept\nPa",
"device Model": "iPhone7,2",
"helper": "OpenPageAsync",
"route": "//TabBar12/Tab9/HelpTab/HelpTab/IntroductionPage/HelpTab/Concept"
},

I've got the same exception in my app when user starts a "back" swipe from a page, but do not complete the movement.

I don't know how to solve it.

It doesn't work on Xamarin.Forms 4.4.0.991265 but work good on Xamarin.Forms 4.3.0.908675

@jcarlosgbarett Thanks for your comment. I can also confirm that this bug doesn't occur on version 4.3.0.908675 of Xamarin.Forms. I've downgraded from version 4.4.0.991477.

I'm getting this error, again, on XF 4.6. This error is not finished right? @samhouts

Application.Main (System.String[] args)

SIGABRT: Nav Stack consistency error


IShellSectionController.SendPopping (System.Threading.Tasks.Task poppingCompleted)
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state)
NSAsyncSynchronizationContextDispatcher.Apply ()
(wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)
UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)
Application.Main (System.String[] args)

Just got a crash report on XF 4.8.0.1269

iPhone OS 14.0.1 (18A393)

System.Exception: Nav Stack consistency error
  at Xamarin.Forms.ShellSection.Xamarin.Forms.IShellSectionController.SendPopping (System.Threading.Tasks.Task poppingCompleted)
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state)
  at Foundation.NSAsyncSynchronizationContextDispatcher.Apply ()
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)
  at Application.Main (System.String[] args)

got a crash report on XF 4.8.0.1534

iPhone 7 (14.0.1)

Xamarin Exception Stack:
System.Exception: Nav Stack consistency error
at Xamarin.Forms.ShellSection.Xamarin.Forms.IShellSectionController.SendPopping (System.Threading.Tasks.Task poppingCompleted) <0x104a70390 + 0x0006c> in :0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) <0x10468d280 + 0x00053> in <85a0be741dba4068b8b83c4563af7fa8#e8ddf16cd65926822935ababb92240ae>:0
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () <0x1054e5920 + 0x0002b> in :0
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) <0x10548d850 + 0x0002f> in :0
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) <0x10548d7c0 + 0x00043> in :0
at TMSF.iOS.Application.Main (System.String[] args) <0x104504aa0 + 0x00023> in :0

Was this page helpful?
0 / 5 - 0 ratings