Xamarin Forms Inconsistent 'Page must not already have a parent' crash

63 Views Asked by At

When navigation buttons are clicked way to quickly in an app the app used to crash, as Xamarin would get confused about which page to add and try to push or popto one that didn't exist. This bug has been fixed by identifying when Xamarin does not know which page to add to the stack, and forcing a reset by clearing the navigation stack, and starting again from the splash page. Upon triggering this reset, and then trying to press a navigation button the program will sometimes crash and receive a 'page must not already have a parent' error. This crash is inconsistent, sometimes it will occur after the first reset, sometimes it takes 4 or 5 resets for it to occur which is making it hard to debug. It never occurs before a reset has happened.

So far have tried:

  • Following the navigation stack throughout the program, but this is behaving as expected (even after the button clicking crash reset)
  • Looking at the parents of each item in the navigation stack after the crash (these are all NavigationPages and don't appear to be causing any issues)
  • Verified that the code is never adding a page to the navigation stack that already exists

Out of ideas and have been at this for 3 days, what's throwing me the most is that this is inconsistent.

1

There are 1 best solutions below

0
MistorClinky On

Issue was actually being caused by the reset method. Pages are stored in cache memory depending on a configuration file. These pages were not being cleared when resetting the app, meaning while the app was resetting and going back to the home page, it would eventually navigate to a page that was stored in cache memory, if this page was what caused the reset in the first place then it would load the broken page and crash the app. Resetting the cache memory when resetting the app has fixed this.