xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] ShellConent.IsVisible doesn't work the same as it did in Xamarin.Forms 5.0.0.2012 #14739

Open Jakar510 opened 3 years ago

Jakar510 commented 3 years ago

Description

System.ArgumentException: 'unable to figure out route for: //root/IMPL_page1/page1 Java.Lang.IllegalArgumentException: No view found for id 0x4c (unknown) for fragment ShellItemRenderer{54a97f0}

It used to work on an older version of XF (5.0.0.2012).

On select from the flyout menu, it would choose the first page that is visible and display it. This doesn't work anymore. The crash occurs before the page is even rendered. But the navigation seems to work correctly, so it's choosing the route, but it can't find a view associated with the route?

It also sometimes doesn't render in the flyout menu at all.

<FlyoutItem x:Name="Root"
                    Route="root"
                    FlyoutDisplayOptions="AsSingleItem"
                    Title="Title">
    <ShellContent x:Name="Page1"
                            ContentTemplate="{DataTemplate TypeName=foo}" />
    <ShellContent x:Name="Page2"
                            ContentTemplate="{DataTemplate TypeName=bar}" />
</FlyoutItem>

The only stack trace I was able to get.

[AppCenterCrashes] Unhandled Exception from source=AppDomain
[AppCenterCrashes] Java.Lang.IllegalArgumentException: No view found for id 0x4c (unknown) for fragment ShellItemRenderer{54a97f0} (081e0267-ab9f-4203-a7e7-d86a7e662d72 id=0x4c)
[AppCenterCrashes]   --- End of managed Java.Lang.IllegalArgumentException stack trace ---
[AppCenterCrashes] java.lang.IllegalArgumentException: No view found for id 0x4c (unknown) for fragment ShellItemRenderer{54a97f0} (081e0267-ab9f-4203-a7e7-d86a7e662d72 id=0x4c)
[AppCenterCrashes]  at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:513)
[AppCenterCrashes]  at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
[AppCenterCrashes]  at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
[AppCenterCrashes]  at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
[AppCenterCrashes]  at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
[AppCenterCrashes]  at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
[AppCenterCrashes]  at android.os.Handler.handleCallback(Handler.java:938)
[AppCenterCrashes]  at android.os.Handler.dispatchMessage(Handler.java:99)
[AppCenterCrashes]  at android.os.Looper.loop(Looper.java:246)
[AppCenterCrashes]  at android.app.ActivityThread.main(ActivityThread.java:8595)
[AppCenterCrashes]  at java.lang.reflect.Method.invoke(Native Method)
[AppCenterCrashes]  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
[AppCenterCrashes]  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

Steps to Reproduce

  1. set any Page1.IsVisible or Page2.IsVisible to true and the other to false.
  2. navigate to another page, then back to root, if it even is displayed on the flyout
  3. boom

Expected Behavior

FlyoutItem would select the first child that is IsVisible and show the page on select. Always show up on the flyout menu.

Actual Behavior

Crash before the page is even rendered.

Basic Information

Environment

Show/Hide Visual Studio info ```Microsoft Visual Studio Community 2019 Version 16.11.5 VisualStudio.16.Release/16.11.5+31729.503 Microsoft .NET Framework Version 4.8.04084 Installed Version: Community Visual C++ 2019 00435-60000-00000-AA324 Microsoft Visual C++ 2019 .NET Core Debugging with WSL 1.0 .NET Core Debugging with WSL 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.11.75.64347 ASP.NET and Web Tools 2019 ASP.NET Web Frameworks and Tools 2012 16.11.75.64347 For additional information, visit https://www.asp.net/ ASP.NET Web Frameworks and Tools 2019 16.11.75.64347 For additional information, visit https://www.asp.net/ Azure App Service Tools v3.0.0 16.11.75.64347 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.11.75.64347 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.11.0-4.21403.6+ae1fff344d46976624e68ae17164e0607ab68b10 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.11.21196.2 Provides tools for finding, instantiating and customizing templates in cookiecutter format. Dotfuscator Community Edition 6.3.0+8b29d6f4a2 PreEmptive Protection - Dotfuscator CE 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. IncrediBuild Build Acceleration 1.5.0.13 IncrediBuild effectively reduces compilation and development times by up to 90%. IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info JetBrains ReSharper 2021.2.2 Build 212.0.20211006.155518 JetBrains ReSharper package for Microsoft Visual Studio. For more information about ReSharper, visit http://www.jetbrains.com/resharper. Copyright © 2021 JetBrains, Inc. Linux Core Dump Debugging 1.0.9.31727 Enables debugging of Linux core dumps. 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.10 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 for Visual Studio 2.9 Support for Azure Cloud Services projects 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.2 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.10.15 (552afdf) Support for debugging Mono processes with Visual Studio. Node.js Tools 1.5.30526.3 Commit Hash:c09c81113bcbc86d57943fcdd67e82434263d61d Adds support for developing and debugging Node.js apps in Visual Studio NuGet Package Manager 5.11.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ Office Developer Tools for Visual Studio 16.0.31424.03 Microsoft Office Developer Tools for Visual Studio ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info Python 16.11.21196.2 Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers. Python - Django support 16.11.21196.2 Provides templates and integration for the Django web framework. Python - Profiling support 16.11.21196.2 Profiling support for Python projects. Python - VC Project Support 16.1.19129.1 Provides support for launching C++ projects with Python debugging enabled. Razor (ASP.NET Core) 16.1.0.2122504+13c05c96ea6bdbe550bd88b0bf6cdddf8cde1725 Provides languages services for ASP.NET Core Razor. ResXManager ResXManager Manage localization of all ResX-Based resources in one place. Shows all resources of a solution and let's you edit the strings and their localizations in a well-arranged data grid. SQL Server Data Tools 16.0.62107.28140 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.30526.2002 TypeScript Tools for Microsoft Visual Studio Visual Basic Tools 3.11.0-4.21403.6+ae1fff344d46976624e68ae17164e0607ab68b10 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.31506.176 Visual C++ for Cross Platform Mobile Development (Android) Visual C++ for Cross Platform Mobile Development (iOS) 16.0.31213.239 Visual C++ for Cross Platform Mobile Development (iOS) Visual C++ for Linux Development 1.0.9.31727 Visual C++ for Linux Development Visual F# Tools 16.11.0-beta.21322.6+488cc578cafcd261d90d748d8aaa7b8b091232dc 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.11.4.0 Visual Studio Tools for Unity VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio Windows Template Studio 4.1.21179.1 Windows Template Studio quickly builds a UWP app, using a wizard-based UI to turn your needs into a foundation of Windows 10 patterns and best practices. Workflow Manager Tools 1.0 1.0 This package contains the necessary Visual Studio integration components for Workflow Manager. Xamarin 16.11.000.190 (d16-11@2391ed9) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 16.11.0.17 (remotes/origin/11e0001f0b17269345e80b58fb3adf1ba4efe2cd@11e0001f0) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 16.10.5 (355b57a) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 11.4.0.5 (d16-11/7776c9f) Xamarin.Android Reference Assemblies and MSBuild support. Mono: c633fe9 Java.Interop: xamarin/java.interop/d16-11@48766c0 ProGuard: Guardsquare/proguard/v7.0.1@912d149 SQLite: xamarin/sqlite/3.35.4@85460d3 Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-11@683f375 Xamarin.iOS and Xamarin.Mac SDK 15.0.0.8 (0796d78dc) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```

Screenshots

Reproduction Link

Workaround

Create multiple shell classes, one for each page and config you need, and set the one you need for the Application.Current.MainPage.

jfversluis commented 3 years ago

Hey @Jakar510 we found some things for Shell that we hopefully have fixed (again). The NuGet should be on nuget.org soon, or you could grab it from here for now: https://github.com/xamarin/Xamarin.Forms/releases/tag/release-5.0.0-sr6 just to test it.

Could you maybe try it and see if that fixes it for you?

Jakar510 commented 3 years ago

@jfversluis I just tried with the latest XF (5.0.0.2196)

This occurs when I log out and call Application.Current.MainPage = shell = new AppShell(); By this point the app is already initialized and displays.

I then update any FlyoutItem(s) as needed, such as:

shell.foo.IsVisible  = false;
shell.bar.IsVisible  = true;

If I set the visibility after assigning it to MainPage, I get the following with no stack trace, just a crash:

Java.Lang.IllegalArgumentException: 'No view found for id 0x74 (unknown) for fragment ShellItemRenderer{5e186c8} (2301f220-3b1f-4e30-8a26-ae50fc35e4a1 id=0x74)'

and if I set it before:

System.NullReferenceException: Object reference not set to an instance of an object.
  at Xamarin.HotReload.Xaml.VisualTreeService.VisualTree.DispatcherVisualTreeContext.RemoveElementRecursive (System.Object current) [0x00010] in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Xaml\VisualTreeService\VisualTree\DispatcherVisualTreeContext.cs:792 
  at Xamarin.HotReload.Xaml.VisualTreeService.VisualTree.DispatcherVisualTreeContext.RemoveElementRecursive (System.Object current) [0x0005a] in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Xaml\VisualTreeService\VisualTree\DispatcherVisualTreeContext.cs:806 
  at Xamarin.HotReload.Xaml.VisualTreeService.VisualTree.DispatcherVisualTreeContext.RemoveElementRecursive (System.Object current) [0x0005a] in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Xaml\VisualTreeService\Visua10-18 10:26:31.246 V/mono-stdout(22788):   at Xamarin.HotReload.Xaml.VisualTreeService.VisualTree.DispatcherVisualTreeContext.RemoveElementRecursive (System.Object current) [0x0005a] in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Xaml\VisualTreeService\VisualTree\DispatcherVisualTreeContext.cs:806 
  at Xamarin.HotReload.Xaml.VisualTreeService.VisualTree.DispatcherVisualTreeContext.RemoveElementRecursive (System.Object current) [0x0005a] in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Xaml\VisualTreeService\VisualTree\DispatcherVisualTreeContext.cs:806 
  at Xamarin.HotReload.Xaml.VisualTreeService.VisualTree.DispatcherVisualTreeContext.RemoveElementRecursive (System.Object current) [0x0005a] in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Xaml\VisualTreeService\VisualTree\DispatcherVisualTreeContext.cs:806 
  at TrueLogic.iTrueLogic.Shared.ApplicationShell.AppShell.InitRootShell (TrueLogic.iTrueLogic.Models.RootView root) [0x001ab] in D:\WorkSpace\TrueLogic\s10-18 10:26:31.246 V/mono-stdout(22788):   at Xamarin.HotReload.Xaml.VisualTreeService.VisualTree.DispatcherVisualTreeContext.RemoveElementRecursive (System.Object current) [0x0005a] in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Xaml\VisualTreeService\VisualTree\DispatcherVisualTreeContext.cs:806 
  at Xamarin.HotReload.Xaml.VisualTreeService.VisualTree.DispatcherVisualTreeContext.RemoveElementRecursive (System.Object current) [0x0005a] in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Xaml\VisualTreeService\VisualTree\DispatcherVisualTreeContext.cs:806 
  at Xamarin.HotReload.Xaml.VisualTreeService.VisualTree.DispatcherVisualTreeContext.ProcessRemove (System.Object element) [0x00000] in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Xaml\VisualTreeService\VisualTree\DispatcherVisualTreeContext.cs:767 
  at Xamarin.HotReload.Xaml.VisualTreeService.VisualTree.DispatcherVisualTreeContext.OnApplicationPropertyChanging (System.Object sender, System.ComponentModel.PropertyChangingEventArgs e) [0x00027] in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Xaml\VisualTreeService\VisualTree\DispatcherVisualTreeContext.cs:443 
  at Xamarin.HotReload.Xaml.VisualTreeService.VisualTree.ApplicationWrapper.OnApplicationPropertyChanging (System.Object sender, Xamarin.Forms.PropertyChangingEventArgs e) [0x00000] in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Xaml\VisualTreeService\VisualTree\ApplicationWrapper.cs:73 
  at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangingEventArgs(object,Xamarin.Forms.PropertyChangingEventArgs)
  at Xamarin.Forms.BindableObject.OnPropertyChanging (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:269 
  at Xamarin.Forms.Application.set_MainPage (Xamarin.Forms.Page value) [0x00018] in D:\a\1\s\Xamarin.Forms.Core\Application.cs:77 
  at TrueLogic.iTrueLogic.Shared.ApplicationShell.AppShell.InitRootShell (TrueLogic.iTrueLogic.Models.RootView root) [0x001ab] in D:\WorkSpace\TrueLogic\src\iTrueLogic.Shared\ApplicationShell\AppShell.xaml.cs:92 
  at TrueLogic.iTrueLogic.Shared.GUI.Misc.Settings.ViewModels.GlobalSettingsViewModel.ResetUser (System.Threading.CancellationToken token) [0x00198] in D:\WorkSpace\TrueLogic\src\iTrueLogic.Shared\GUI\Misc\Settings\ViewModels\GlobalSettingsViewModel.cs:167 
Jakar510 commented 3 years ago

I changed Application.Current.MainPage = shell = new AppShell(); to if ( Application.Current.MainPage is not AppShell shell ) { Application.Current.MainPage = shell = new AppShell(); } and it is now doesn't crash, though I don't know how stable it is. I will continue testing.

jfversluis commented 3 years ago

@Jakar510 the latest version just has a little update and is now 2196 so you might try that as well :)

Jakar510 commented 3 years ago

@jfversluis It was a typo on the version. fixed now.

Jakar510 commented 3 years ago

Still getting a crash, on occasion:

FATAL EXCEPTION: Thread-9
Process: com.app.id, PID: 8401
android.runtime.JavaProxyThrowable: System.InvalidOperationException: Content not found for active Xamarin.Forms.FlyoutItem. Title: foo. Route: bar.
  at Xamarin.Forms.Platform.Android.ShellItemRenderer.OnCreateView (Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState) [0x000af] in <78f1e278d6554267b0719153100b0838>:0 
  at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_inflater, System.IntPtr native_container, System.IntPtr native_savedInstanceState) [0x00020] in <3f4916ec151f42d78db35ab229c07e0d>:0 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.109(intptr,intptr,intptr,intptr,intptr)
    at crc643f46942d9dd1fff9.ShellItemRenderer.n_onCreateView(Native Method)
    at crc643f46942d9dd1fff9.ShellItemRenderer.onCreateView(Unknown Source:0)
    at androidx.fragment.app.Fragment.performCreateView(Unknown Source:19)
    at androidx.fragment.app.FragmentStateManager.createView(Unknown Source:188)
    at androidx.fragment.app.FragmentStateManager.moveToExpectedState(Unknown Source:116)
    at androidx.fragment.app.FragmentManager.executeOpsTogether(Unknown Source:277)
    at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(Unknown Source:84)
    at androidx.fragment.app.FragmentManager.execPendingActions(Unknown Source:21)
    at androidx.fragment.app.FragmentManager$5.run(Unknown Source:3)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at androidx.test.espresso.base.Interrogator.loopAndInterrogate(Interrogator.java:10)
    at androidx.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:7)
    at androidx.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:1)
    at androidx.test.espresso.base.UiControllerImpl.injectMotionEvent(UiControllerImpl.java:5)
    at androidx.test.espresso.action.MotionEvents.sendUp(MotionEvents.java:6)
    at androidx.test.espresso.action.MotionEvents.sendUp(MotionEvents.java:1)
    at androidx.test.espresso.action.Tap.sendSingleTap(Tap.java:5)
    at androidx.test.espresso.action.Tap.-$$Nest$smsendSingleTap(Unknown Source:0)
    at androidx.test.espresso.action.Tap$1.sendTap(Tap.java:1)
    at androidx.test.espresso.action.GeneralClickAction.perform(GeneralClickAction.java:4)
    at androidx.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:2)
    at androidx.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:21)
    at androidx.test.espresso.ViewInteraction.-$$Nest$mdoPerform(Unknown Source:0)
    at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:2)
    at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:1)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8016)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
Jakar510 commented 2 years ago

@jfversluis

With Xamarin.Forms v5.0.0.2196:

System.InvalidOperationException: 'Content not found for active Xamarin.Forms.FlyoutItem. Title: Dashboard. Route: dashboard.'

With Xamarin.Forms v5.0.0.2244:

Shell Navigation is ignored; It always goes to the first page in the Shell class, even if it's not visible and navigating to another page.

jfversluis commented 2 years ago

Would you be able to demonstrate this in a reproduction sample?

Jakar510 commented 2 years ago

I will try to get a repo.