unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.79k stars 706 forks source link

Frame.InnerNavigate() throws null ref exception on navigation to Page #4412

Closed robloo closed 3 years ago

robloo commented 3 years ago

Current behavior

The code crashes here:

https://github.com/unoplatform/uno/blob/c4eaf68fee3502e5847446251412787ccea67ce7/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.cs#L292

The issue is Instance is still null because no Page has been navigated-to/loaded before.

This situation likely occurs when the first Page fails to load for some reason. However, Uno should be robust in this situation. If a previous page fails to load, it should still be possible to navigate to another Page.

Expected behavior

According to the Page.OnNavigatingFrom(NavigatingCancelEventArgs) docs:

https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.page.onnavigatingfrom?view=winrt-19041

Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.

Therefore, if the page stack is empty this method call can safely be ignored. Simply check for null before invoking here.

How to reproduce it (as minimally and precisely as possible)

N/A

Workaround

??

Environment

Nuget Package:

Nuget Package Version(s):

Affected platform(s):

IDE:

Relevant plugins:

Anything else we need to know?

jeromelaban commented 3 years ago

Thanks for the report. Is the page you're navigating to or from having an OnNavigatingFrom as well ?

robloo commented 3 years ago

@jeromelaban No, I don't use OnNavigatingFrom() in any of the pages so haven't checked this. I'm also guessing the first page is failing to load which puts navigation in the state that can cause this error. I think it should be possible to load/navigate-to other pages if such an error occurs though.