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 to a empty Xamarin.Forms.TabbedPage results in NullReferenceException #2576

Closed
bakerhillpins opened this issue Oct 7, 2021 · 4 comments

Comments

@bakerhillpins
Copy link

bakerhillpins commented Oct 7, 2021

Description

Navigation to a Tabbed Page that doesn't have any tabs will result in a NullReferenceException. Adding a tab in Xaml or using data binding with an ItemsSource/ItemTemplate will work. See the TheTabbedPage.xaml file, at the top you can un-comment the xaml to remove the exception.

This occurs on iOS and Android

I suppose that an empty tab page isn't an overly common issue with runtime, however, during development when I am working through my business object development work the lack of items in a collection isn't rare. This particular issue took me quite some time determine it was simply an issue of a lack of items in my ItemsSource because I didn't have any of that plumbed up yet.

Steps to Reproduce

  1. Download and run the sample project.
  2. Select the flyout page.
  3. Select the "TheTabbedPage" option.
  4. If you are running the VS debugger it will break on the failed navigation at Line 155 of AppMapViewModelBase.cs

Expected Behavior

No exception. Xamarin.Forms on it's own has no issues displaying an empty TabbedPage.

Actual Behavior

Navigation fails with the following exception captured in the INavigationResult object:


> [0:] System.NullReferenceException: Object reference not set to an instance of an object.
>   at Prism.Navigation.PageNavigationService.OnNavigatedTo (Xamarin.Forms.Page toPage, Prism.Navigation.INavigationParameters parameters) [0x0002d] in /_/src/Forms/Prism.Forms/Navigation/PageNavigationService.cs:813 
>   at Prism.Navigation.PageNavigationService.DoNavigateAction (Xamarin.Forms.Page fromPage, System.String toSegment, Xamarin.Forms.Page toPage, Prism.Navigation.INavigationParameters parameters, System.Func`1[TResult] navigationAction, System.Action`1[T] onNavigationActionCompleted) [0x001ba] in /_/src/Forms/Prism.Forms/Navigation/PageNavigationService.cs:773 
>   at Prism.Navigation.PageNavigationService.UseReverseNavigation (Xamarin.Forms.Page currentPage, System.String nextSegment, System.Collections.Generic.Queue`1[T] segments, Prism.Navigation.INavigationParameters parameters, System.Nullable`1[T] useModalNavigation, System.Boolean animated) [0x00289] in /_/src/Forms/Prism.Forms/Navigation/PageNavigationService.cs:1088 
>   at Prism.Navigation.PageNavigationService.ProcessNavigationForNavigationPage (Xamarin.Forms.NavigationPage currentPage, System.String nextSegment, System.Collections.Generic.Queue`1[T] segments, Prism.Navigation.INavigationParameters parameters, System.Nullable`1[T] useModalNavigation, System.Boolean animated) [0x003a3] in /_/src/Forms/Prism.Forms/Navigation/PageNavigationService.cs:597 
>   at Prism.Navigation.PageNavigationService.ProcessNavigation (Xamarin.Forms.Page currentPage, System.Collections.Generic.Queue`1[T] segments, Prism.Navigation.INavigationParameters parameters, System.Nullable`1[T] useModalNavigation, System.Boolean animated) [0x00259] in /_/src/Forms/Prism.Forms/Navigation/PageNavigationService.cs:414 
>   at Prism.Navigation.PageNavigationService.ProcessNavigationForFlyoutPage (Xamarin.Forms.FlyoutPage currentPage, System.String nextSegment, System.Collections.Generic.Queue`1[T] segments, Prism.Navigation.INavigationParameters parameters, System.Nullable`1[T] useModalNavigation, System.Boolean animated) [0x0061b] in /_/src/Forms/Prism.Forms/Navigation/PageNavigationService.cs:711 
>   at Prism.Navigation.PageNavigationService.ProcessNavigation (Xamarin.Forms.Page currentPage, System.Collections.Generic.Queue`1[T] segments, Prism.Navigation.INavigationParameters parameters, System.Nullable`1[T] useModalNavigation, System.Boolean animated) [0x00406] in /_/src/Forms/Prism.Forms/Navigation/PageNavigationService.cs:426 
>   at Prism.Navigation.PageNavigationService.NavigateInternal (System.Uri uri, Prism.Navigation.INavigationParameters parameters, System.Nullable`1[T] useModalNavigation, System.Boolean animated) [0x000f9] in /_/src/Forms/Prism.Forms/Navigation/PageNavigationService.cs:359 

Basic Information

  • Version with issue: 8.1.97 with DryIoc
  • Last known good version:
  • Xamarin.Forms version: 5.0.0.2125
  • IDE:

Reproduction Link

TabPageExcept.zip

@bakerhillpins bakerhillpins changed the title Navigation to a empty TabbedPage results in NullReferenceException Navigation to a empty Xamarin.Forms.TabbedPage results in NullReferenceException Oct 7, 2021
@brianlagunas
Copy link
Member

A TabbedPage is required to have a Tab. Prism always assumes there is as least one. I'm not completely opposed to changing this, but I'm not sure it really makes sense to. It's an easy fix for this particular issue regarding OnNavigatedTo/From. But, this is not an assumption I want to change throughout the entire NavigationService. @dansiegel what are your feelings on this?

@brianlagunas
Copy link
Member

I submitted a PR to fix this. If @dansiegel approves we can add support for this specific scenario.

@bakerhillpins
Copy link
Author

bakerhillpins commented Oct 7, 2021

A TabbedPage is required to have a Tab. Prism always assumes there is as least one. I'm not completely opposed to changing this, but I'm not sure it really makes sense to. It's an easy fix for this particular issue regarding OnNavigatedTo/From. But, this is not an assumption I want to change throughout the entire NavigationService. @dansiegel what are your feelings on this?

@brianlagunas
That was precisely why I mentioned that Xamarin Forms on it's own supports a tabbed page with no Tabs. That was probably the 1st test I performed when debugging.

I submitted a PR to fix this. If @dansiegel approves we can add support for this specific scenario.

Thank you.

@brianlagunas
Copy link
Member

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants