Hey!
I had some issues with the use of Navigation in my Xamarin.Forms app on a barcode scanner page, which was luckily solved here: https://docs.microsoft.com/en-us/answers/questions/520601/xamarinforms-navigationpushasync-34only-the-origin.html
Now I have a new problem with this change, which I didn't had before. When a barcode is scanned on this page, based on the page where the user is coming from (SourcePage), the app navigates to the correct next page with the results. Somehow the app does this perfectly the first time, but it crashes the second time.
Let's say that I open the barcode scanner from the MainPage which will direct me to Page1 after the scan, the stack will look like MainPage -> BarcodeScannerPage -> Page1. The problem with this is that when the user presses the back-button on Page1, the app returns to the BarcodeScannerPage obviously. To make sure it goes back to the main page, I remove the BarcodeScannerPage in the stack which leads to: MainPage -> Page1. Now the user returns to the MainPage as it should be.
Here comes the problem: the first time this works, the second time it crashes with the following exception:

This error is pretty strange, since it implies that there is less items in the stack than the code is asking for, but if I open de barcode scanner the first time leading to a stack of MainPage -> BarcodeScannerPage -> Page1, I suppose this stack will be created again when I open the barcode scanner for a second time from the MainPage.
Does someone know how to solve this? Is there maybe a better way to remove the page from the stack?