Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug][Shell] Shell.Current.GoToAsync exception on certain navigation sequence #12958

Open
tschramme86 opened this issue Nov 24, 2020 · 21 comments

Comments

@tschramme86
Copy link

Description

The Shell.Current.GoToAsync method fails on a particular navigation sequence with Exception

System.ArgumentNullException: 'Shell Content Page is Null
Parameter name: page'

Inner Stack Trace:

  at Xamarin.Forms.Platform.Android.ShellSectionRenderer.UpdateCurrentItem (Xamarin.Forms.ShellContent content) [0x00013] in D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ShellSectionRenderer.cs:95 
  at Xamarin.Forms.Platform.Android.ShellSectionRenderer.Android.Support.V4.View.ViewPager.IOnPageChangeListener.OnPageScrolled (System.Int32 position, System.Single positionOffset, System.Int32 positionOffsetPixels) [0x0001c] in D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ShellSectionRenderer.cs:38 
  at Android.Support.V4.View.ViewPager+IOnPageChangeListenerInvoker.n_OnPageScrolled_IFI (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 position, System.Single positionOffset, System.Int32 positionOffsetPixels) [0x00008] in <c4d4704d3494459fba644f7558bc2b06>:0 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.50(intptr,intptr,int,single,int)

Steps to Reproduce

  1. Create an App with the following Shell Hierarchy
    <TabBar>
        <Tab Title="Tab 1" Route="welcome" Icon="icon_about">
            <ShellContent Title="MainPage" Route="landing" ContentTemplate="{DataTemplate local:Page1}" />
        </Tab>
        <Tab Title="Tab 2" Route="profile" Icon="icon_about">
            <ShellContent Title="Page 2" Route="main" ContentTemplate="{DataTemplate local:Page2}" />
            <ShellContent Title="Page 3" Route="details" ContentTemplate="{DataTemplate local:Page3}" />
            <ShellContent Title="Page 4" Route="settings" ContentTemplate="{DataTemplate local:Page4}" />
        </Tab>
    </TabBar>
  1. Put two Buttons onto Page2 with the following event handlers
        private async void BtnGotoPage3(object sender, EventArgs e)
        {
            await Shell.Current.GoToAsync("//profile/details");
        }

        private async void BtnGotoPage4(object sender, EventArgs e)
        {
            await Shell.Current.GoToAsync("//profile/settings");
        }
  1. Start the App and do exactly the following Navigation Steps:
    3.1. App is opened -> Page1 is shown initially
    3.2. Click in the bottom Tab bar onto the second Tab labeled "Tab 2" -> Page2 is shown
    3.3. Now click the second Button that triggers the BtnGotoPage4event handler

Expected Behavior

The App navigates to Page 4

Actual Behavior

The above mentioned exception is thrown in the EventHandler at line await Shell.Current.GoToAsync("//profile/settings"); when the navigation steps are executed exactly in the written order.

Please note:
The navigation works + exception is not thrown when

  • After Step 3.2 you first go to Page 3 manually by using the top Tab-Bar, go back to Page 2 and then click the second Button
  • After Step 3.2 you first go to Page 4 manually by using the top Tab-Bar, go back to Page 2 and then click the second Button
  • After Step 3.2 you first go to Page 3 by using the first Button (await Shell.Current.GoToAsync("//profile/details"); is executed), go back to Page 2 and then click the second button

Also the navigation to Page 3 with the first Button (await Shell.Current.GoToAsync("//profile/details");) works in all cases. It never throws an exception.

Basic Information

  • Version with issue:
  • Last known good version: n/a
  • Platform Target Frameworks:
    • Android: 9.0 / 10.0
  • NuGet Packages: Xamarin.Forms 4.8.0.1687
  • Affected Devices: Nokia 8, Google Pixel 4, Android Emulator

Environment

Microsoft Visual Studio Professional 2019
Version 16.8.2
VisualStudio.16.Release/16.8.2+30717.126
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Professional

Visual C++ 2019   00435-20000-00004-AA461
Microsoft Visual C++ 2019

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools 2019   16.8.553.28003
ASP.NET and Web Tools 2019

ASP.NET Core Razor Language Services   16.1.0.2052803+84e121f1403378489b842e1797df2f3f5a49ac3c
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2019   16.8.553.28003
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   16.8.553.28003
Azure App Service Tools v3.0.0

Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio   2.6.3000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   16.8.553.28003
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.6.3000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   3.8.0-5.20567.16+53c5d7d3cf13d88978744a32a27c5f8350a8400a
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter   16.8.20241.2
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Fabric.DiagnosticEvents   1.0
Fabric Diagnostic Events

GitHub.VisualStudio   2.11.106.19330
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

JetBrains ReSharper 2020.2.4   Build 202.0.20200925.65451
JetBrains ReSharper package for Microsoft Visual Studio. For more information about ReSharper, visit http://www.jetbrains.com/resharper. Copyright © 2020 JetBrains, Inc.

Microsoft Azure HDInsight Azure Node   2.6.3000.0
HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service   2.6.3000.0
Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio   16.0
Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service   2.6.3000.0
Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node   1.0
Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30924.1

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.1.113+g422d40002e.RR
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   16.8.43 (00471f8)
Support for debugging Mono processes with Visual Studio.

Node.js Tools   1.5.20902.1 Commit Hash:b474efcb6f92db52a8f8e2e6a8cb9648476885cc
Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager   5.8.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Python   16.8.20241.2
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Python - Conda support   16.8.20241.2
Conda support for Python projects.

Python - Django support   16.8.20241.2
Provides templates and integration for the Django web framework.

Python - IronPython support   16.8.20241.2
Provides templates and integration for IronPython-based projects.

Python - Profiling support   16.8.20241.2
Profiling support for Python projects.

SettingsCommands Extension   1.0
SettingsCommands Visual Studio Extension Detailed Info

SQL Server Data Tools   16.0.62010.06180
Microsoft SQL Server Data Tools

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   16.0.21016.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.8.0-5.20567.16+53c5d7d3cf13d88978744a32a27c5f8350a8400a
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual C++ for Cross Platform Mobile Development (Android)   16.0.30608.117
Visual C++ for Cross Platform Mobile Development (Android)

Visual C++ for Cross Platform Mobile Development (iOS)   16.0.30608.117
Visual C++ for Cross Platform Mobile Development (iOS)

Visual C++ for Linux Development   1.0.9.30608
Visual C++ for Linux Development

Visual F# Tools   16.8.0-beta.20507.4+da6be68280c89131cdba2045525b80890401defd
Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

Visual Studio Tools for Kubernetes   1.0
Visual Studio Tools for Kubernetes

Visual Studio Tools for Unity   4.8.2.0
Visual Studio Tools for Unity

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Foo   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.8.000.255 (d16-8@d002176)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.8.0.507 (remotes/origin/d16-8@e87b24884)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.8.112 (86385a3)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   11.1.0.17 (d16-8/c0e2b8e)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: be2226b
    Java.Interop: xamarin/java.interop/d16-8@79d9533
    ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000
    SQLite: xamarin/sqlite/3.32.1@1a3276b
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc


Xamarin.iOS and Xamarin.Mac SDK   14.4.1.3 (e30c41de3)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Screenshots

Screenshot 2020-11-24 120347
Screenshot 2020-11-24 120443

Reproduction Link

ShellNavigationSample.zip

@tschramme86 tschramme86 added s/unverified New report that has yet to be verified t/bug 🐛 labels Nov 24, 2020
@hartez hartez added a/navigation a/shell 🐚 e/5 🕔 5 and removed s/unverified New report that has yet to be verified labels Nov 26, 2020
@joehage9
Copy link

joehage9 commented Jun 9, 2021

any fix found?

@tschramme86
Copy link
Author

@joehage9 Not from my side. And I don't see any progress in the Xamarin.Forms project at all. Almost no updates here in the repository for weeks or even months and no new package versions. Seems that everybody is just focussing on .NET 6 MAUI. What I can understand a little bit on the one hand - but what is also not fair to the community on the other hand. So many people relied on XF for their projects. So many open bugs. So many open pull requests by the community without any reaction from the team. And when this situation will really last until November when .NET 6 will be released (fingers crossed), it has been almost a year without real updates/fixes.
At least some official communication about this situation would be nice. What do you think @samhouts ?

@pictos
Copy link
Contributor

pictos commented Jun 10, 2021

@tschramme86
Copy link
Author

@pictos I cannot access that link. Website says "VS402939: Release with ID 2843 does not exist. Specify a valid ID and try again."

@pictos
Copy link
Contributor

pictos commented Jun 10, 2021

@PureWeen is there a way to access that nuget? Is related to #13648

@PureWeen
Copy link
Contributor

Hmm @pictos it looks like our nightlies aren't running

Try grabbing the nuget off of here
https://dev.azure.com/xamarin/public/_build/results?buildId=41405&view=artifacts&pathAsName=false&type=publishedArtifacts

See if that works

@pictos
Copy link
Contributor

pictos commented Jun 10, 2021

cc: @tschramme86 @joehage9 /\

@tschramme86
Copy link
Author

@PureWeen @pictos Thank you for your effort.
I was able to download the newest package from the provided Azure link and updated the example project of this issue.
But although the project is now on Xamarin.Forms 5.0.0.7300 the error is still there.

image

@pictos
Copy link
Contributor

pictos commented Jun 13, 2021

@tschramme86 thanks for testing this version. I'll se if can take a look at it this week or next week

@tschramme86
Copy link
Author

@pictos just fyi: Issue is not solved with latest 5.0.0-sr4 available from today.

@cjkarande
Copy link

cjkarande commented Aug 2, 2021

In my case for Xamarin.Forms (5.0.2012), Shell.Current.GoToAsync throws Null pointer exception. Error dump below.

This is a SHOWSTOPPER. Can someone from Xamarin please clarify on this?


[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
[mono-rt] at Xamarin.Forms.ShellNavigationManager.GoToAsync (Xamarin.Forms.ShellNavigationParameters shellNavigationParameters) [0x007c1] in D:\a\1\s\Xamarin.Forms.Core\Shell\ShellNavigationManager.cs:166

@LeonSweden
Copy link

I do also experience the very same behavior when calling:
await Shell.Current.GoToAsync("//pages/logbook/cloud")

Having hierrachy defined in AppShell:
FlyoutItem Route="pages"
Tab Route="logbook"
ShellContent Route="cloud"

Exception:
{System.ArgumentNullException: Shell Content Page is Null
Parameter name: page
at Xamarin.Forms.Platform.Android.ShellSectionRenderer.UpdateCurrentItem (Xamarin.Forms.ShellContent content) [0x00013] in D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ShellSectionRenderer.cs:83
at Xamarin.Forms.Platform.Android.ShellSectionRenderer.AndroidX.ViewPager.Widget.ViewPager.IOnPageChangeListener.OnPageScrolled (System.Int32 position, System.Single positionOffset, System.Int32 positionOffsetPixels) [0x0001c] in D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ShellSectionRenderer.cs:26
at AndroidX.ViewPager.Widget.ViewPager+IOnPageChangeListenerInvoker.n_OnPageScrolled_IFI (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 position, System.Single positionOffset, System.Int32 positionOffsetPixels) [0x00008] in D:\a\1\s\generated\androidx.viewpager.viewpager\obj\Release\monoandroid9.0\generated\src\AndroidX.ViewPager.Widget.ViewPager.cs:563
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.93(intptr,intptr,int,single,int)}

@LuisiitoDev
Copy link

I am having a related issue, with the last Xamarin update (5.0.0.2337), I am getting the follow error:
image
I am registering the routes using Routing.RegisterRoute and in the XAML as well.

@imsam67
Copy link

imsam67 commented Mar 16, 2022

@LuisiitoDev Have you resolved this issue? I have the same exact problem. I'm trying to do this from an event handler in AppShell.

@CDM-Jones
Copy link

I'm having the exact same issue detailed above from other users. Anyone from the Xamarin team keen to advise?

@CDM-Jones
Copy link

@joehage9 Not from my side. And I don't see any progress in the Xamarin.Forms project at all. Almost no updates here in the repository for weeks or even months and no new package versions. Seems that everybody is just focussing on .NET 6 MAUI. What I can understand a little bit on the one hand - but what is also not fair to the community on the other hand. So many people relied on XF for their projects. So many open bugs. So many open pull requests by the community without any reaction from the team. And when this situation will really last until November when .NET 6 will be released (fingers crossed), it has been almost a year without real updates/fixes. At least some official communication about this situation would be nice. What do you think @samhouts ?

Completely agree.

@samhouts
Copy link
Member

@LeonSweden
Copy link

Also reported on https://developercommunity.visualstudio.com/t/XAMARIN:-ShellCurrentGoToAsync-excepti/10089980

Still not fixed. This makes me wonder (after more than 2 years and still not fixed) if its ever gonna be fixed.

@LeonSweden
Copy link

LeonSweden commented Oct 11, 2022 via email

@AdamDiament
Copy link

AdamDiament commented Aug 21, 2023

The only workaround I have found is to manually use Shell.Current.GoToAsync to go to the second tab first, then do the original navigation to the tab you actually want to go to. It's clunky and slow, but less clunky and slow than the app crashing! I recommend setting "animate: false" in the first GoToAsync call too to increase speed and avoid the user having to watch the second page loading then going away.

Does anyone have a better workaround?

@macakmujo
Copy link

macakmujo commented Dec 10, 2023

experiencing same thing on .NET MAUI as well when switching between 2 pages constantyly until it brakes

at WinRT.ExceptionHelpers.g__Throw|39_0(Int32 hr)
at ABI.Microsoft.UI.Xaml.Controls.IFrameMethods.Navigate(IObjectReference _obj, Type sourcePageType, Object parameter, NavigationTransitionInfo infoOverride)
at Microsoft.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter, NavigationTransitionInfo infoOverride)
at Microsoft.Maui.Platform.StackNavigationManager.NavigateTo(NavigationRequest args)
at Microsoft.Maui.Controls.Handlers.ShellSectionHandler.RequestNavigation(ShellSectionHandler handler, IStackNavigation view, Object arg3)
at Microsoft.Maui.CommandMapper.InvokeCore(String key, IElementHandler viewHandler, IElement virtualView, Object args)
at Microsoft.Maui.Handlers.ElementHandler.Invoke(String command, Object args)
at Microsoft.Maui.Controls.ShellSection.Microsoft.Maui.IStackNavigation.RequestNavigation(NavigationRequest eventArgs)
at Microsoft.Maui.Controls.Handlers.ShellSectionHandler.SyncNavigationStack(Boolean animated, NavigationRequestedEventArgs e)
at Microsoft.Maui.Controls.Handlers.ShellSectionHandler.MapCurrentItem(ShellSectionHandler handler, ShellSection item)
at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
at Microsoft.Maui.Controls.Handlers.ShellSectionHandler.SetVirtualView(IElement view)
at Microsoft.Maui.Controls.Handlers.ShellItemHandler.UpdateCurrentItem()
at Microsoft.Maui.Controls.Handlers.ShellItemHandler.MapCurrentItem(ShellItemHandler handler, ShellItem item)
at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
at Microsoft.Maui.Controls.Handlers.ShellItemHandler.SetVirtualView(IElement view)
at Microsoft.Maui.Controls.Platform.ShellView.CreateShellItemView()
at Microsoft.Maui.Controls.Platform.ShellView.SwitchShellItem(ShellItem newItem, Boolean animate)
at Microsoft.Maui.Controls.Handlers.ShellHandler.MapCurrentItem(ShellHandler handler, Shell view)
at Microsoft.Maui.Controls.Element.OnPropertyChanged(String propertyName)
at Microsoft.Maui.Controls.Shell.OnPropertyChanged(String propertyName)
at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent)
at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)
at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value, SetterSpecificity specificity)
at Microsoft.Maui.Controls.Element.SetValueFromRenderer(BindableProperty property, Object value)
at Microsoft.Maui.Controls.ShellNavigationManager.d__14.MoveNext()
at PointOfSale.AppShell.d__5.MoveNext() in D:\DEVELOPMENT\PO\src\PointOfSale\AppShell.xaml.cs:line 31

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

No branches or pull requests