Bug 31366 - Pushing and then popping a page modally cause ArgumentOutOfRangeException
Summary: Pushing and then popping a page modally cause ArgumentOutOfRangeException
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.4.3
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: E.Z. Hart [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2015-06-24 19:18 UTC by Sergey Komisarchik
Modified: 2015-10-27 19:41 UTC (History)
12 users (show)

Tags: ac navigationpage navigation
Is this bug a regression?: ---
Last known good build:


Attachments
Test case (597.02 KB, application/octet-stream)
2015-06-24 19:23 UTC, Sergey Komisarchik
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Sergey Komisarchik 2015-06-24 19:18:19 UTC
Seems like this is a regression due to this bugfix:
https://bugzilla.xamarin.com/show_bug.cgi?id=29363

Here scenario a bit different:
1. Navigate from Page1 to Page2 using modal navigation
2. In Page2 invoke PopModalAsync() using Page2's (important) Navigation property OR press the Back button.
3. If time between 1 and 2 is little (for example fast press to Back button after navigation to Page2) then it throws with ArgumentOutOfRangeException

The problem is that in Appearing event of the Page2 ModalStack of the Page2's Navigation doesn't contain Page2 yet and out of sync with Page1's Navigation (which is updated).

Complete minimal example:

public class App : Application
{
    public App()
    {
        var page1 = new Page();
        var page2Factory = new Func<Page>(
            () =>
                {
                    var page = new Page();
                    page.Appearing += async delegate {
                        {
                            await Task.Yield();
                            Debug.Assert(page1.Navigation.ModalStack.Count > 0); // true
                            Debug.Assert(page.Navigation.ModalStack.Count > 0);  // failed
                            await page.Navigation.PopModalAsync(); // throws ArgumentOutOfRangeException
                        }
                    };
                    return page;
                });

        page1.Appearing += (_, __) => page1.Navigation.PushModalAsync(page2Factory());

        this.MainPage = page1;
    }
}
Comment 1 Sergey Komisarchik 2015-06-24 19:22:59 UTC
Tested in WP8 SL / Android
Comment 2 Sergey Komisarchik 2015-06-24 19:23:27 UTC
Created attachment 11732 [details]
Test case
Comment 3 Lionel Ong 2015-08-24 21:51:15 UTC
This is occurring with Xamarin.Forms version 1.4.4.6392 for iOS also.
Comment 4 Rui Marinho 2015-10-14 14:52:51 UTC
Should be fixed in 1.5.2-pre1
Comment 5 Parmendra Kumar 2015-10-26 09:57:00 UTC
I have checked this issue with Xamarin.Forms 1.5.2-pre1 and its working fine.
I am not getting any exception with X.F 1.5.2-pre1.

Hence closing this issue.
Comment 6 Lionel Ong 2015-10-27 19:40:20 UTC
Which version will the fix be in?
Comment 7 Lionel Ong 2015-10-27 19:41:23 UTC
Please ignore that last message.