Open RobotGizmo opened 3 years ago
@RobotGizmo can you provide the code you are using to add the FlyoutItem?
It'd be useful to see where in the life cycle you are adding it and what the structure of the FlyoutItem you are adding is?
I'll see what I can provide, it's all very inter-connected. Here is the XAML definition for the FlyoutItem:
<FlyoutItem Route="root" x:Name="shlRoot" FlyoutDisplayOptions="AsMultipleItems">
<ShellContent Route="main" x:Name="shlMain" ContentTemplate="{DataTemplate bf:BFXShellHomePage}"></ShellContent>
</FlyoutItem>
And here is the code that adds the items:
this.shlRoot.Items.Clear();
ShellContent allGroups = new ShellContent();
allGroups.Title = this._allGroupsDisplayName;
allGroups.ContentTemplate = this._defaultPageTemplateCache;
this.shlRoot.Items.Add(allGroups); <-it throws the NullReferenceException on this line
Please let me know if I can provide any more information. Thanks!
I just wanted to let you know that I updated to the latest version of Xamarin Forms and the issue is still present, if that helps at all. (5.0.0.1905+599-sha.51ca97b92-azdo.4376726)
@RobotGizmo if instead of clearing out the Items you set "IsVisible" to false does that still crash?
If I set it to IsVisible=false
then I get a routing error somewhere else in the code. If I just comment out the this.shlRoot.Items.Clear();
line it doesn't crash with the NullRef exception.
Description
This line needs a null check: https://github.com/xamarin/Xamarin.Forms/blob/9090bcc44e499fcaa9959d39e574f132c802f047/Xamarin.Forms.Platform.iOS/Renderers/ShellItemRenderer.cs#L355
Right now it's this:
SelectedViewController = renderer.ViewController;
I believe it should be this because the if statement above is ignoring the null:
SelectedViewController = renderer?.ViewController;
Here is the stack trace pointing at this line:
0x29 in Xamarin.Forms.Platform.iOS.ShellItemRenderer.GoTo at D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ShellItemRenderer.cs:355,5 C# 0x23 in Xamarin.Forms.Platform.iOS.ShellItemRenderer.OnElementPropertyChanged at D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ShellItemRenderer.cs:180,5 C# 0x12 in Xamarin.Forms.BindableObject.OnPropertyChanged at D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:266,7 C# 0x2 in Xamarin.Forms.Element.OnPropertyChanged at D:\a\1\s\Xamarin.Forms.Core\Element.cs:362,4 C# 0x2 in Xamarin.Forms.BaseShellItem.OnPropertyChanged at D:\a\1\s\Xamarin.Forms.Core\Shell\BaseShellItem.cs:235,4 C# 0x11B in Xamarin.Forms.BindableObject.SetValueActual at D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:510,5 C# 0x17C in Xamarin.Forms.BindableObject.SetValueCore at D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:446,5 C# 0x5 in Xamarin.Forms.BindableObject.SetValueCore at D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:383,7 C# 0x4 in Xamarin.Forms.Element.SetValueFromRenderer at D:\a\1\s\Xamarin.Forms.Core\Element.cs:248,4 C# 0x1D in Xamarin.Forms.ShellItem.OnVisibleChildAdded at D:\a\1\s\Xamarin.Forms.Core\Shell\ShellItem.cs:240,5 C# 0x68 in Xamarin.Forms.ShellItem.<.ctor>b__16_0 at D:\a\1\s\Xamarin.Forms.Core\Shell\ShellItem.cs:140,7 C# 0x7C in Xamarin.Forms.ShellElementCollection.OnVisibleItemsChanged at D:\a\1\s\Xamarin.Forms.Core\Shell\ShellElementCollection.cs:58,4 C# 0x1B in System.Collections.ObjectModel.ObservableCollection<Xamarin.Forms.ShellSection>.OnCollectionChanged at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263,21 C# 0x9 in System.Collections.ObjectModel.ObservableCollection<Xamarin.Forms.ShellSection>.OnCollectionChanged at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:338,13 C# 0x23 in System.Collections.ObjectModel.ObservableCollection<Xamarin.Forms.ShellSection>.InsertItem at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:196,13 C# 0x2A in System.Collections.ObjectModel.Collection<Xamarin.Forms.ShellSection>.Insert at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:116,13 C# 0x24 in System.Collections.ObjectModel.Collection<Xamarin.Forms.ShellSection>.System.Collections.IList.Insert at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:354,17 C# 0x40 in Xamarin.Forms.ShellElementCollection.CheckVisibility at D:\a\1\s\Xamarin.Forms.Core\Shell\ShellElementCollection.cs:193,7 C# 0x30 in Xamarin.Forms.ShellElementCollection.InnerCollectionChanged at D:\a\1\s\Xamarin.Forms.Core\Shell\ShellElementCollection.cs:152,6 C# 0x9E in Xamarin.Forms.ObservableWrapper<Xamarin.Forms.Element,Xamarin.Forms.ShellSection>.ListOnCollectionChanged at D:\a\1\s\Xamarin.Forms.Core\ObservableWrapper.cs:179,6 C# 0x1B in System.Collections.ObjectModel.ObservableCollection<Xamarin.Forms.Element>.OnCollectionChanged at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263,21 C# 0x9 in System.Collections.ObjectModel.ObservableCollection<Xamarin.Forms.Element>.OnCollectionChanged at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:338,13 C# 0x23 in System.Collections.ObjectModel.ObservableCollection<Xamarin.Forms.Element>.InsertItem at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:196,13 C# 0x23 in System.Collections.ObjectModel.Collection<Xamarin.Forms.Element>.Add at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:71,13 C# 0x5C in Xamarin.Forms.ObservableWrapper<Xamarin.Forms.Element,Xamarin.Forms.ShellSection>.Add at D:\a\1\s\Xamarin.Forms.Core\ObservableWrapper.cs:35,4 C# 0x7 in Xamarin.Forms.ShellElementCollection<Xamarin.Forms.ShellSection>.Add at D:\a\1\s\Xamarin.Forms.Core\Shell\ShellElementCollection.cs:307,51 C#
Steps to Reproduce
I'm sorry, this project is too complicated and I can't repro it with a simple project. This only happens in iOS though.
Expected Behavior
It should check the null or use ? to ignore it.
Actual Behavior
It fails to check the null and throws a NullReferenceException.
Basic Information
Environment
Show/Hide Visual Studio info
``` Microsoft Visual Studio Professional 2019 Version 16.8.4 VisualStudio.16.Release/16.8.4+30907.101 Microsoft .NET Framework Version 4.8.04084 Installed Version: Professional Visual C++ 2019 00435-60000-00000-AA911 Microsoft Visual C++ 2019 ASP.NET and Web Tools 2019 16.8.557.25636 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.557.25636 For additional information, visit https://www.asp.net/ AutoFormatPackage Extension 1.0 AutoFormatPackage Visual Stuido Extension Detailed Info Azure App Service Tools v3.0.0 16.8.557.25636 Azure App Service Tools v3.0.0 Azure Functions and Web Jobs Tools 16.8.557.25636 Azure Functions and Web Jobs Tools C# Tools 3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Code Cleanup On Save 1.0.8 Automatically run one of the Code Clean profiles when saving the document. This ensures your code is always formatted correctly and follows your coding style conventions. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. EmptyLineCommand Extension 1.0 EmptyLineCommand Visual Studio Extension Detailed Info Extensibility Message Bus 1.2.6 (master@34d6af2) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. 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 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. NuGet Package Manager 5.8.1 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 RealClean Extension 1.0 RealClean Visual Stuido Extension Detailed Info SettingsPackage Extension 1.0 SettingsPackage Visual Stuido Extension Detailed Info SQL Server Data Tools 16.0.62012.31170 Microsoft SQL Server Data Tools 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. TypeScript Tools 16.0.21016.2001 TypeScript Tools for Microsoft Visual Studio Visual Basic Tools 3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. 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 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 VisualSVN 7.3.0 Integration with Subversion version control. For more information about VisualSVN, see the VisualSVN website at https://www.visualsvn.com Copyright © 2020 VisualSVN Software Ltd. All rights reserved. VSColorOutput 2.73 Color output for build and debug windows - https://mike-ward.net/vscoloroutput Xamarin 16.8.000.261 (d16-8@bb99248) 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.26 (d16-8/a36ce73) Xamarin.Android Reference Assemblies and MSBuild support. Mono: 5e9cb6d 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.8.0.3 (c51fabee8) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```