dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.03k stars 1.73k forks source link

App crashes with GetRoute NRE when FlyoutItemIsVisible changes #16940

Open BretJohnson opened 1 year ago

BretJohnson commented 1 year ago

Description

When toggling FlyoutItemIsVisible, the app can crash with a NullReferenceException in GetRoute. This fails at least on WinUI - not sure about other platforms.

This is an issue that @spadapet originally reported here https://github.com/dotnet/maui/issues/10468#issuecomment-1684255255, now split out to a separate bug.

REPRO:

Open solution F5 to build and run on Windows Click the one button that appears in the running app UI RESULT: NullReferenceException, in MAUI GetRoute code.

Callstack:

Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Routing.GetRoute(Microsoft.Maui.Controls.BindableObject obj)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Routing.IsImplicit(Microsoft.Maui.Controls.BindableObject source)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Platform.ShellView.SwitchShellItem(Microsoft.Maui.Controls.ShellItem newItem, bool animate)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Handlers.ShellHandler.MapCurrentItem(Microsoft.Maui.Controls.Handlers.ShellHandler handler, Microsoft.Maui.Controls.Shell view)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper<Microsoft.Maui.Controls.Shell, Microsoft.Maui.Controls.Handlers.ShellHandler>.Add.AnonymousMethod__0(Microsoft.Maui.IElementHandler h, Microsoft.Maui.IElement v)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdatePropertyCore(string key, Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdateProperty(Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView, string property)
Microsoft.Maui.dll!Microsoft.Maui.Handlers.ElementHandler.UpdateValue(string property)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Handlers.ShellHandler.MapItems(Microsoft.Maui.Controls.Handlers.ShellHandler handler, Microsoft.Maui.Controls.Shell view)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper<Microsoft.Maui.Controls.Shell, Microsoft.Maui.Controls.Handlers.ShellHandler>.Add.AnonymousMethod__0(Microsoft.Maui.IElementHandler h, Microsoft.Maui.IElement v)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdatePropertyCore(string key, Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdateProperty(Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView, string property)
Microsoft.Maui.dll!Microsoft.Maui.Handlers.ElementHandler.UpdateValue(string property)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Shell..ctor.AnonymousMethod__154_3(object _, System.Collections.Specialized.NotifyCollectionChangedEventArgs __)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.OnVisibleItemsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
System.ObjectModel.dll!System.Collections.ObjectModel.ObservableCollection<Microsoft.Maui.Controls.ShellItem>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection<Microsoft.Maui.Controls.ShellItem>.Remove(Microsoft.Maui.Controls.ShellItem item)
System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection<Microsoft.Maui.Controls.ShellItem>.System.Collections.IList.Remove(object value)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.CheckVisibility(Microsoft.Maui.Controls.BaseShellItem element)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.OnShellElementControllerItemsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.OnVisibleItemsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
System.ObjectModel.dll!System.Collections.ObjectModel.ObservableCollection<Microsoft.Maui.Controls.ShellSection>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection<Microsoft.Maui.Controls.ShellSection>.Remove(Microsoft.Maui.Controls.ShellSection item)
System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection<Microsoft.Maui.Controls.ShellSection>.System.Collections.IList.Remove(object value)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.CheckVisibility(Microsoft.Maui.Controls.BaseShellItem element)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.OnShellElementControllerItemsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.OnVisibleItemsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
System.ObjectModel.dll!System.Collections.ObjectModel.ObservableCollection<Microsoft.Maui.Controls.ShellContent>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection<Microsoft.Maui.Controls.ShellContent>.Remove(Microsoft.Maui.Controls.ShellContent item)
System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection<Microsoft.Maui.Controls.ShellContent>.System.Collections.IList.Remove(object value)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.CheckVisibility(Microsoft.Maui.Controls.BaseShellItem element)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.BaseShellItemPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindableObject.OnPropertyChanged(string propertyName)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.OnPropertyChanged(string propertyName)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BaseShellItem.OnPropertyChanged(string propertyName)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindableObject.SetValueActual(Microsoft.Maui.Controls.BindableProperty property, Microsoft.Maui.Controls.BindableObject.BindablePropertyContext context, object value, bool currentlyApplying, Microsoft.Maui.Controls.Internals.SetValueFlags attributes, Microsoft.Maui.Controls.SetterSpecificity specificity, bool silent)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindableObject.SetValueCore(Microsoft.Maui.Controls.BindableProperty property, object value, Microsoft.Maui.Controls.Internals.SetValueFlags attributes, Microsoft.Maui.Controls.BindableObject.SetValuePrivateFlags privateAttributes, Microsoft.Maui.Controls.SetterSpecificity specificity)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.ApplyCore(object sourceObject, Microsoft.Maui.Controls.BindableObject target, Microsoft.Maui.Controls.BindableProperty property, bool fromTarget, Microsoft.Maui.Controls.SetterSpecificity specificity)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.Apply(bool fromTarget)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.BindingExpressionPart.PropertyChanged.AnonymousMethod__50_0()
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.DispatcherExtensions.DispatchIfRequired(Microsoft.Maui.Dispatching.IDispatcher dispatcher, System.Action action)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.BindingExpressionPart.PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs args)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.WeakPropertyChangedProxy.OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
>   MauiApp4.dll!MauiApp4.ViewModel.ShowStuff.set(bool value) Line 18
MauiApp4.dll!MauiApp4.MainPage.OnCounterClicked(object sender, System.EventArgs e) Line 14

Steps to Reproduce

See description

Link to public reproduction project repository

https://github.com/dotnet/maui/files/12381764/TestAppThatHitsNullReference.zip

Version with bug

8.0.0-preview.7.8842

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows, I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

Not yet

Relevant log output

No response

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.