Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation.PushAsync(); on windows platform throws exception: Catastrophic failure (0x8000FFFF (E_UNEXPECTED)) with same page instance #8123

Closed
mfe- opened this issue Jun 16, 2022 · 4 comments
Labels
area-navigation NavigationPage platform/windows 🪟 s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working

Comments

@mfe-
Copy link

mfe- commented Jun 16, 2022

Description

Navigation.PushAsync(); throws exception: Catastrophic failure (0x8000FFFF (E_UNEXPECTED)) on the windows platform if a singleton instance of the page is provided. Cannot reproduced on android.

The issue still exists see #3931

Steps to Reproduce

Repo Steps: https://github.com/mfe-/MauiApp1-Noinstalledcomponentsweredetected

  1. create a new dotnet maui project with visual studio 2022
  2. add a second contentpage (in this repo the name of the second contentpage is NewGamePage.xaml
  3. In App.xaml.cs replace MainPage = new MainPage() with MainPage = new NavigationPage(new MainPage());
  4. In MainPage.xaml.cs replace the content of OnCounterClicked with
        public static Page page;
        private void OnCounterClicked(object sender, EventArgs e)
        {
            try
            {
                count++;
                CounterLabel.Text = $"Current count: {count}";
                SemanticScreenReader.Announce(CounterLabel.Text);
                if (App.Current.MainPage is NavigationPage navigationPage)
                {
                    if (MainPage.page == null)
                    {
                        MainPage.page = new NewGamePage();
                    }
                    navigationPage.CurrentPage.Navigation.PushAsync(MainPage.page);
                }
            }
            catch(Exception ex)
            {
                System.Console.WriteLine(ex);
            }

        }
  1. build and run the app on the windows platform
  2. click on button click me
  3. click left arrow back button
  4. click again on click me
  5. App.g.i.cs throws
  6. exception: Catastrophic failure (0x8000FFFF (E_UNEXPECTED)) Microsoft.UI.Xaml.Controls.Frame.NavigationFailed was unhandled.

Version with bug

6.0.312

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

10.0.19041

Did you find any workaround?

If you use navigationPage.CurrentPage.Navigation.PushAsync(new NewGamePage()) you won't run into the issue so it looks like it can't handle PushAsync with the same instance.

Relevant log output

No response

@mfe- mfe- added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Jun 16, 2022
@PureWeen
Copy link
Member

@mfe- this isn't really a supported scenario. If it works on Android that's just out of luck.

The fix here would probably be to throw an exception on Android so all the platforms react the same way with a better error message

@Eilon Eilon added the area-navigation NavigationPage label Jun 16, 2022
@mfe-
Copy link
Author

mfe- commented Jun 17, 2022

@PureWeen I used to register my Pages as singleton in my previous UWP apps. This worked on the uwp platform, so I'm wondering why this is not a supported scenario.

@Keflon
Copy link

Keflon commented Jun 17, 2022

@PureWeen - Hello :) I too register my pages as singletons.

I do this for good reason - creating pages can be expensive, and if they are properly decoupled from their data they are fully reusable simply by replacing their BindingContext (or just leaving it be, depending).

I have used this approach in a number of commercial Xamarin.Forms applications without any problem.
Sample application here showing singleton page registration: https://github.com/Keflon/MvvmZeroTutorialApp#locatorcs please refer to Locator.cs

For clarity:

  • I don't expect to ever have the same page-instance in a navigation-stack multiple times.
  • I do expect to be able to push a page instance, pop it, then re-push the same page instance.

I'm hoping your '... this isn't really supported ...' refers to the former, not the latter! :)

I have ported the above MvvmZero library to MAUI and I'm waiting on this problem being fixed before publishing.
I've made a bug reporting the same problem here: #7698.

@PureWeen
Copy link
Member

PureWeen commented Jun 20, 2022

@mfe- From the code I was thinking you were pushing the same instance onto the stack multiple times.

If what @Keflon outlines here is true

  • I don't expect to ever have the same page-instance in a navigation-stack multiple times.
  • I do expect to be able to push a page instance, pop it, then re-push the same page instance.

Then yes that's a supported scenario and should be fixed :-)

Closing as a duplicate

@ghost ghost locked as resolved and limited conversation to collaborators Jul 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-navigation NavigationPage platform/windows 🪟 s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants