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.18k stars 1.74k forks source link

App is crashing on using "Share" word in MenuFlyoutSubItem #16618

Closed theRealGupta closed 1 year ago

theRealGupta commented 1 year ago

Description

Hi Dev,

On creation on a menu using keyword "Share" app is crashing

<FlyoutBase.ContextFlyout>

                                        <MenuFlyout x:Name="RightClickMenu">

                                            <!--Share-->

                                            <MenuFlyoutSubItem Text="Share" Command="{Binding ShareCommand}">
                                                         <MenuFlyoutItem Text="Facebook"
                                                           Command="{Binding ShareFacebookCommand}"/>
                                            </MenuFlyoutSubItem>
                                            <!--Create-->

                                            <MenuFlyoutSubItem Text="Create" Command="{Binding CreateAlbumCommand}">

                                            </MenuFlyoutSubItem>

                                            <!--Delete-->
                                            <MenuFlyoutItem Text="Delete" Command="{Binding DeleteCommand}"/>

                                        </MenuFlyout>
                                    </FlyoutBase.ContextFlyout>

As you can see I am using "Share" Key word in MenuFlyoutSubItem Text Field using this key word crashing the app on right Click

CRASH REPORT

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Maui.Platform.MenuExtensions.ToPlatformMenu(IList1 menuElements, String title, IImageSource imageSource, IMauiContext mauiContext, IUIMenuBuilder uIMenuBuilder) at Microsoft.Maui.Handlers.MenuFlyoutSubItemHandler.CreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler2[[Microsoft.Maui.IMenuFlyoutSubItem, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[UIKit.UIMenu, Microsoft.MacCatalyst, Version=16.4.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].OnCreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler.CreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.MenuExtensions.ToPlatformMenu(IList1 menuElements, IMauiContext mauiContext) at Microsoft.Maui.Handlers.MenuFlyoutHandler.CreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler2[[Microsoft.Maui.IMenuFlyout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[UIKit.UIMenu, Microsoft.MacCatalyst, Version=16.4.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].OnCreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler.CreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.MauiUIContextMenuInteraction.GetConfigurationForMenu() at Microsoft.Maui.Platform.MauiUIContextMenuInteraction.FlyoutUIContextMenuInteractionDelegate.GetConfigurationForMenu(UIContextMenuInteraction interaction, CGPoint location) at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) at PhotoScannerApp.Program.Main(String[] args) in /Users/anupg/workSpace/MindFire/AmbirTechnology/PhotoScanner/PhotoScannerApp/PhotoScannerApp/Platforms/MacCatalyst/Program.cs:line 13 2023-08-09 10:14:42.749 PhotoScannerApp[35055:4844862] Unhandled managed exception: Object reference not set to an instance of an object. (System.NullReferenceException) at Microsoft.Maui.Platform.MenuExtensions.ToPlatformMenu(IList1 menuElements, String title, IImageSource imageSource, IMauiContext mauiContext, IUIMenuBuilder uIMenuBuilder) at Microsoft.Maui.Handlers.MenuFlyoutSubItemHandler.CreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler2[[Microsoft.Maui.IMenuFlyoutSubItem, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[UIKit.UIMenu, Microsoft.MacCatalyst, Version=16.4.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].OnCreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler.CreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.MenuExtensions.ToPlatformMenu(IList1 menuElements, IMauiContext mauiContext) at Microsoft.Maui.Handlers.MenuFlyoutHandler.CreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler2[[Microsoft.Maui.IMenuFlyout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[UIKit.UIMenu, Microsoft.MacCatalyst, Version=16.4.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].OnCreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler.CreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.MauiUIContextMenuInteraction.GetConfigurationForMenu() at Microsoft.Maui.Platform.MauiUIContextMenuInteraction.FlyoutUIContextMenuInteractionDelegate.GetConfigurationForMenu(UIContextMenuInteraction interaction, CGPoint location) at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) at PhotoScannerApp.Program.Main(String[] args) in /Users/anupg/workSpace/MindFire/AmbirTechnology/PhotoScanner/PhotoScannerApp/PhotoScannerApp/Platforms/MacCatalyst/Program.cs:line 13

================================================================= Native Crash Reporting

Got a SIGABRT while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application.

================================================================= Native stacktrace:

===========================================================

Repro

https://github.com/theRealGupta/MAUI-Bug-FlyoutMenu

ghost commented 1 year ago

Hi @theRealGupta. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

theRealGupta commented 1 year ago

this is code for MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="FlyoutMenu.MainPage">

    <Label Text="Right click here">

        <FlyoutBase.ContextFlyout>

            <MenuFlyout x:Name="RightClickMenu" >
                <!--Add to Album-->

                <MenuFlyoutSubItem Text ="Add to Album" >
                    <MenuFlyoutItem Text="Create New"/>
                </MenuFlyoutSubItem>
                <!--Save-->

                <MenuFlyoutItem Text="Save" />

                <!--Share-->

                <MenuFlyoutSubItem Text="Share">
                    <MenuFlyoutItem Text="Facebook"/>
                    <MenuFlyoutItem Text="Twitter"/>
                </MenuFlyoutSubItem>

                <!--Delete-->
                <MenuFlyoutItem Text="Delete" />

            </MenuFlyout>

        </FlyoutBase.ContextFlyout>

    </Label>

</ContentPage>

and no other code is required to test this You can noticed here I used "Share" keyword in MenuFlyoutSubItem if i change this app will not crash otherwise it will crash

theRealGupta commented 1 year ago

This is complete Project to test the bug https://github.com/theRealGupta/MAUI-Bug-FlyoutMenu

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.

AnnYang01 commented 1 year ago

Verified this on Visual Studio Enterprise 17.8.0 Preview 1.0 in Windows 11, it not repro on .NET 8.0 and .NET7.0 using below Project. FlyoutMenu.zip FlyoutMenu

ghost commented 1 year ago

Hi @theRealGupta. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.