1

Main page of my app is checking for user information. Based on some condition, popup shows, that navigates to a page with a webview. I navigate to it using standard approach:

await Shell.Current.Navigation.PushAsync(new BindCardPage(user.uid), false);

But when I start an app for the first time, after trying to navigate to a webview page NRE is thrown:

System.NullReferenceException: Object reference not set to an instance of an object.
 at Xamarin.Forms.ShellSection.OnPushAsync (Xamarin.Forms.Page page, System.Boolean animated) [0x00013] in D:\a\1\s\Xamarin.Forms.Core\Shell\ShellSection.cs:514 
 at Xamarin.Forms.ShellSection+NavigationImpl.OnPushAsync (Xamarin.Forms.Page page, System.Boolean animated) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Shell\ShellSection.cs:714 
 at Xamarin.Forms.Internals.NavigationProxy.PushAsync (Xamarin.Forms.Page root, System.Boolean animated) [0x00013] in D:\a\1\s\Xamarin.Forms.Core\NavigationProxy.cs:117 
 at Xamarin.Forms.Shell+NavigationImpl.OnPushAsync (Xamarin.Forms.Page page, System.Boolean animated) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Shell\Shell.cs:1161 
 at Xamarin.Forms.Internals.NavigationProxy.PushAsync (Xamarin.Forms.Page root, System.Boolean animated) [0x00013] in D:\a\1\s\Xamarin.Forms.Core\NavigationProxy.cs:117 

But when I start an app again (condition didn't change) same popup navigates to a page with no problems. I tried adding an empty constructor and setting a default value, but it didn't help. Looked at the breakpoints - all of my data, that I pass is not null, WebView component is also not null. This is a wierd bug and I don't know what to do with it

My Xamarin.Forms version is 4.4.0.991537

Community
  • 1
  • 1
Anton Motin
  • 51
  • 1
  • 7
  • I use Navigation.PushAsync to navigate new contentpage that having webview control, but I don't have any issue in Xamarin.Shell, so can you provide your sample that can reproduce your issue at github, I will download your sample to test at my side? – Cherry Bu - MSFT Mar 12 '20 at 07:20
  • @CherryBu-MSFT After several rebuilds and clean builds, everything randomly started working, but still, this is some problem with Shell itself, IMO – Anton Motin Mar 18 '20 at 12:50
  • If you still have this issue, I suggest you can provide one sample and some screenshot at github for xamarin, because I can not reproduce your issue at my side. – Cherry Bu - MSFT Mar 24 '20 at 05:33

1 Answers1

0

Had a similar crash, now the issue seems to be that shell is pushing a null page into the NavStack in version 4.2.xxx and above which is very annoying but it is what it is. I was able to solve this btw by writing the following code in the OnBackButtonPressed of my Apps Shell class.

    protected override bool OnBackButtonPressed()
    {
        if (Application.Current.MainPage.GetType() == typeof(AppShell) && Shell.Current.Navigation.NavigationStack.Where(x => x != null).Any())
        {
            return base.OnBackButtonPressed();
        }
        else
        {
            System.Diagnostics.Process.GetCurrentProcess().CloseMainWindow();
            return true;
        }
    } 

Where AppShell is my custom Shell class.

Goodluck feel free to get back if you have any questions

FreakyAli
  • 13,349
  • 3
  • 23
  • 63