Xamarin.Forms Shell应用程序首次启动时出现导航错误

Xamarin.Forms Shell应用程序首次启动时出现导航错误,xamarin,xamarin.forms,xamarin.shell,Xamarin,Xamarin.forms,Xamarin.shell,我的应用程序主页正在检查用户信息。根据某些条件,弹出窗口显示,可导航到具有webview的页面。我使用标准方法导航到它: await Shell.Current.Navigation.PushAsync(new BindCardPage(user.uid), false); 但当我第一次启动应用程序时,在尝试导航到webview页面后,会抛出NRE: System.NullReferenceException: Object reference not set to an instance o

我的应用程序主页正在检查用户信息。根据某些条件,弹出窗口显示,可导航到具有webview的页面。我使用标准方法导航到它:

await Shell.Current.Navigation.PushAsync(new BindCardPage(user.uid), false);
但当我第一次启动应用程序时,在尝试导航到webview页面后,会抛出NRE:

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 
但当我再次启动一个应用程序(条件没有改变)时,相同的弹出窗口会导航到一个没有问题的页面。我尝试添加一个空构造函数并设置一个默认值,但没有帮助。查看断点-我传递的所有数据都不为null,WebView组件也不为null。这是一个wierd bug,我不知道该怎么处理它


我的Xamarin.Forms版本是
4.4.0.991537

有类似的崩溃,现在的问题似乎是shell在版本4.2.xxx和更高版本中将一个空页推到NavStack中,这非常烦人,但事实就是如此。顺便说一句,我可以在我的Apps外壳类的
OnBackButtonPressed
中编写以下代码来解决这个问题

    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;
        }
    } 
其中AppShell是我的自定义Shell类

    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;
        }
    } 

Goodluck如果您有任何问题,请随时回来

不幸的是,这不起作用,我在应用程序的第一次启动时仍然会遇到该漏洞。我认为这是Xamarin的问题,我必须提出一个问题…添加完整的错误堆栈跟踪,并向我们显示它中断的代码行!设置不同版本的后,错误消失xamarin@AntonMotin,它是什么版本,我可以添加它作为其他搜索相同内容的人的答案。我使用Navigation.PushAsync导航具有webview控件的新内容页,但Xamarin.Shell中没有任何问题,那么你能提供你的样本在github重现你的问题吗?我会下载你的样本在我这边测试?@CherryBu MSFT经过几次重建和清理构建后,所有东西都随机开始工作,但这仍然是Shell本身的一些问题,如果你仍然有这个问题,我建议您可以在github为xamarin提供一个示例和一些屏幕截图,因为我无法在我这边复制您的问题。