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.27k stars 1.76k forks source link

Setting MenuFlyoutSubItem IconImageSource throws a NullReferenceException #25893

Open molesmoke opened 1 week ago

molesmoke commented 1 week ago

Description

Setting MenuFlyoutSubItem IconImageSource throws a NullReferenceException

Steps to Reproduce

Add the following to a MenuFlyout:

<MenuFlyoutSubItem IconImageSource="dotnet_bot.png" Text="Test" />

Actual: Throws a NullReferenceException:

Expected: MenuFlyoutSubItem displayed with the given icon

MenuFlyoutItems work OK:

<MenuFlyoutItem IconImageSource="dotnet_bot.png" Text="Test" />

Link to public reproduction project repository

https://github.com/molesmoke/MauiTestApp/tree/net9.0-menuflyoutsubitem-nre

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.100 SR10

Affected platforms

Windows

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.ApplyStyleSheets(System.Collections.Generic.List<Microsoft.Maui.Controls.StyleSheets.StyleSheet> sheets, Microsoft.Maui.IVisualTreeElement element) Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.ApplyStyleSheets(System.Collections.Generic.List<Microsoft.Maui.Controls.StyleSheets.StyleSheet> sheets, Microsoft.Maui.IVisualTreeElement element) Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.ApplyStyleSheets()  Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.OnParentSet()   Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.SetParent(Microsoft.Maui.Controls.Element value)    Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.OnChildAdded(Microsoft.Maui.Controls.Element child) Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.AddLogicalChild(Microsoft.Maui.Controls.Element element)    Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.MenuFlyout.Add(Microsoft.Maui.IMenuElement item)    Unknown
    [Lightweight Function]  
    System.Private.CoreLib.dll!System.Reflection.MethodBaseInvoker.InvokeWithOneArg(object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object[] parameters, System.Globalization.CultureInfo culture)  Unknown
    Microsoft.Maui.Controls.Xaml.dll!Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.Visit(Microsoft.Maui.Controls.Xaml.ElementNode node, Microsoft.Maui.Controls.Xaml.INode parentNode)    Unknown
    Microsoft.Maui.Controls.Xaml.dll!Microsoft.Maui.Controls.Xaml.ElementNode.Accept(Microsoft.Maui.Controls.Xaml.IXamlNodeVisitor visitor, Microsoft.Maui.Controls.Xaml.INode parentNode)  Unknown
    Microsoft.Maui.Controls.Xaml.dll!Microsoft.Maui.Controls.Xaml.ElementNode.Accept(Microsoft.Maui.Controls.Xaml.IXamlNodeVisitor visitor, Microsoft.Maui.Controls.Xaml.INode parentNode)  Unknown
    Microsoft.Maui.Controls.Xaml.dll!Microsoft.Maui.Controls.Xaml.ElementNode.Accept(Microsoft.Maui.Controls.Xaml.IXamlNodeVisitor visitor, Microsoft.Maui.Controls.Xaml.INode parentNode)  Unknown
    Microsoft.Maui.Controls.Xaml.dll!Microsoft.Maui.Controls.Xaml.ElementNode.Accept(Microsoft.Maui.Controls.Xaml.IXamlNodeVisitor visitor, Microsoft.Maui.Controls.Xaml.INode parentNode)  Unknown
    Microsoft.Maui.Controls.Xaml.dll!Microsoft.Maui.Controls.Xaml.RootNode.Accept(Microsoft.Maui.Controls.Xaml.IXamlNodeVisitor visitor, Microsoft.Maui.Controls.Xaml.INode parentNode) Unknown
    Microsoft.Maui.Controls.Xaml.dll!Microsoft.Maui.Controls.Xaml.XamlLoader.Visit(Microsoft.Maui.Controls.Xaml.RootNode rootnode, Microsoft.Maui.Controls.Xaml.HydrationContext visitorContext, bool useDesignProperties)  Unknown
    Microsoft.Maui.Controls.Xaml.dll!Microsoft.Maui.Controls.Xaml.XamlLoader.Load(object view, string xaml, System.Reflection.Assembly rootAssembly, bool useDesignProperties)  Unknown
    Microsoft.Maui.Controls.Xaml.dll!Microsoft.Maui.Controls.Xaml.XamlLoader.Load(object view, string xaml, bool useDesignProperties)   Unknown
    Microsoft.Maui.Controls.Xaml.dll!Microsoft.Maui.Controls.Xaml.XamlLoader.Load(object view, System.Type callingType) Unknown
    Microsoft.Maui.Controls.Xaml.dll!Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml<MauiTestApp.MainPage>(MauiTestApp.MainPage view, System.Type callingType) Unknown
>   MauiTestApp.dll!MauiTestApp.MainPage.InitializeComponent() Line 27  C#
    MauiTestApp.dll!MauiTestApp.MainPage.MainPage() Line 7  C#
    [Lightweight Function]  
    System.Private.CoreLib.dll!System.Reflection.ConstructorInvoker.InvokeImpl(object arg1, object arg2, object arg3, object arg4)  Unknown
    System.Private.CoreLib.dll!System.Reflection.ConstructorInvoker.Invoke(System.Span<object> arguments)   Unknown
    Microsoft.Extensions.DependencyInjection.Abstractions.dll!Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(System.IServiceProvider provider)   Unknown
    Microsoft.Extensions.DependencyInjection.Abstractions.dll!Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(System.IServiceProvider provider, System.Type instanceType, object[] parameters)   Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellContent.Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent.AnonymousMethod__0()    Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ElementTemplate.CreateContent() Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Internals.DataTemplateExtensions.CreateContent(Microsoft.Maui.Controls.DataTemplate self, object item, Microsoft.Maui.Controls.BindableObject container)    Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellContent.Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent()   Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Handlers.ShellContentHandler.CreatePlatformElement()    Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Handlers.ElementHandler<System.__Canon, System.__Canon>.OnCreatePlatformElement() Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Handlers.ElementHandler.CreatePlatformElement()   Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(Microsoft.Maui.IElement view)  Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.SetHandler(Microsoft.Maui.IElementHandler newHandler)   Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.Handler.set(Microsoft.Maui.IElementHandler value)   Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Platform.ElementExtensions.ToHandler(Microsoft.Maui.IElement view, Microsoft.Maui.IMauiContext context)   Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Platform.ElementExtensions.ToPlatform(Microsoft.Maui.IElement view, Microsoft.Maui.IMauiContext context)  Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Handlers.ShellSectionHandler.SyncNavigationStack(bool animated, Microsoft.Maui.Controls.Internals.NavigationRequestedEventArgs e)   Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Handlers.ShellSectionHandler.MapCurrentItem(Microsoft.Maui.Controls.Handlers.ShellSectionHandler handler, Microsoft.Maui.Controls.ShellSection item)    Unknown
    Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper<Microsoft.Maui.Controls.ShellSection, Microsoft.Maui.Controls.Handlers.ShellSectionHandler>.Add.AnonymousMethod__0(Microsoft.Maui.IElementHandler h, Microsoft.Maui.IElement v)    Unknown
    Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdatePropertyCore(string key, Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView)    Unknown
    Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdateProperties(Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView)  Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(Microsoft.Maui.IElement view)  Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Handlers.ShellSectionHandler.SetVirtualView(Microsoft.Maui.IElement view)   Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.SetHandler(Microsoft.Maui.IElementHandler newHandler)   Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.Handler.set(Microsoft.Maui.IElementHandler value)   Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Platform.ElementExtensions.ToHandler(Microsoft.Maui.IElement view, Microsoft.Maui.IMauiContext context)   Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Handlers.ShellItemHandler.UpdateCurrentItem()   Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Handlers.ShellItemHandler.MapCurrentItem(Microsoft.Maui.Controls.Handlers.ShellItemHandler handler, Microsoft.Maui.Controls.ShellItem item) Unknown
    Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper<Microsoft.Maui.Controls.ShellItem, Microsoft.Maui.Controls.Handlers.ShellItemHandler>.Add.AnonymousMethod__0(Microsoft.Maui.IElementHandler h, Microsoft.Maui.IElement v)  Unknown
    Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdatePropertyCore(string key, Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView)    Unknown
    Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdateProperties(Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView)  Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(Microsoft.Maui.IElement view)  Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Handlers.ShellItemHandler.SetVirtualView(Microsoft.Maui.IElement view)  Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.SetHandler(Microsoft.Maui.IElementHandler newHandler)   Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.Handler.set(Microsoft.Maui.IElementHandler value)   Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Platform.ElementExtensions.ToHandler(Microsoft.Maui.IElement view, Microsoft.Maui.IMauiContext context)   Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Platform.ShellView.CreateShellItemView()    Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Platform.ShellView.SwitchShellItem(Microsoft.Maui.Controls.ShellItem newItem, bool animate) Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Handlers.ShellHandler.MapCurrentItem(Microsoft.Maui.Controls.Handlers.ShellHandler handler, Microsoft.Maui.Controls.Shell view) Unknown
    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)  Unknown
    Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdatePropertyCore(string key, Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView)    Unknown
    Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdateProperties(Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView)  Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(Microsoft.Maui.IElement view)  Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Handlers.ViewHandler<System.__Canon, System.__Canon>.SetVirtualView(Microsoft.Maui.IView view)    Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Handlers.ShellHandler.SetVirtualView(Microsoft.Maui.IView view) Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Handlers.ViewHandler<System.__Canon, System.__Canon>.SetVirtualView(Microsoft.Maui.IElement view) Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.SetHandler(Microsoft.Maui.IElementHandler newHandler)   Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.Handler.set(Microsoft.Maui.IElementHandler value)   Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.Handler.set(Microsoft.Maui.IElementHandler value) Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Platform.ElementExtensions.ToHandler(Microsoft.Maui.IElement view, Microsoft.Maui.IMauiContext context)   Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Platform.ElementExtensions.ToPlatform(Microsoft.Maui.IElement view, Microsoft.Maui.IMauiContext context)  Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Handlers.WindowHandler.MapContent(Microsoft.Maui.Handlers.IWindowHandler handler, Microsoft.Maui.IWindow window)  Unknown
    Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper<Microsoft.Maui.IWindow, Microsoft.Maui.Handlers.IWindowHandler>.Add.AnonymousMethod__0(Microsoft.Maui.IElementHandler h, Microsoft.Maui.IElement v)    Unknown
    Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdatePropertyCore(string key, Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView)    Unknown
    Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdateProperties(Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView)  Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(Microsoft.Maui.IElement view)  Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.SetHandler(Microsoft.Maui.IElementHandler newHandler)   Unknown
    Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.Handler.set(Microsoft.Maui.IElementHandler value)   Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Platform.ElementExtensions.SetHandler(WinRT.IWinRTObject nativeElement, Microsoft.Maui.IElement element, Microsoft.Maui.IMauiContext context) Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Platform.ElementExtensions.SetWindowHandler(Microsoft.UI.Xaml.Window platformWindow, Microsoft.Maui.IWindow window, Microsoft.Maui.IMauiContext context)  Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Microsoft.UI.Xaml.Application platformApplication, Microsoft.Maui.IApplication application, Microsoft.Maui.Handlers.OpenWindowRequest args)   Unknown
    Microsoft.Maui.dll!Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Microsoft.UI.Xaml.Application platformApplication, Microsoft.Maui.IApplication application, Microsoft.UI.Xaml.LaunchActivatedEventArgs args)  Unknown
    Microsoft.Maui.dll!Microsoft.Maui.MauiWinUIApplication.OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)  Unknown
    Microsoft.WinUI.dll!Microsoft.UI.Xaml.Application.Microsoft.UI.Xaml.IApplicationOverrides.OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)   Unknown
    Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.IApplicationOverrides.Do_Abi_OnLaunched_0(nint thisPtr, nint args)    Unknown
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.IApplicationStaticsMethods.Start(WinRT.IObjectReference _obj, Microsoft.UI.Xaml.ApplicationInitializationCallback callback)   Unknown
    Microsoft.WinUI.dll!Microsoft.UI.Xaml.Application.Start(Microsoft.UI.Xaml.ApplicationInitializationCallback callback)   Unknown
    MauiTestApp.dll!MauiTestApp.WinUI.Program.Main(string[] args) Line 26   C#
ninachen03 commented 6 days ago

This issue has been verified using Visual Studio 17.13.0 Preview 1(9.0.0-rc.2.24503.2 & 9.0.10). Can repro this issue at android platform. but no throws a NullReferenceException on 8.0.100 Image

jsuarezruiz commented 6 days ago

Notes from a quick review. The MenuFlyoutSubItem have an incorrect null child in the LogicalChildren. Maybe related with this change https://github.com/dotnet/maui/commit/09d3049829d5d6be6db87de511726dce4ac24cdf

jsuarezruiz commented 4 days ago

Notes from a quick review. The MenuFlyoutSubItem have an incorrect null child in the LogicalChildren. Maybe related with this change 09d3049

Not related. The regression comes from https://github.com/dotnet/maui/pull/24688