Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException with a platform-specific GestureRecognizer #24900

Closed
Jean-RobertLaffineur opened this issue Sep 24, 2024 · 5 comments · Fixed by #25008
Closed

NullReferenceException with a platform-specific GestureRecognizer #24900

Jean-RobertLaffineur opened this issue Sep 24, 2024 · 5 comments · Fixed by #25008
Assignees
Labels
area-gestures Gesture types fixed-in-8.0.92 i/regression This issue described a confirmed regression on a currently supported version platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@Jean-RobertLaffineur
Copy link

Description

On Windows (didn't check the other platforms), a NullReferenceException occurs when adding a GestureRecognizer that is conditioned by an OnPlatform, such as no GestureRecognizer is defined in the current (Windows) platform:

<Border>
    <Border.GestureRecognizers>
        <OnPlatform x:TypeArguments="GestureRecognizer">
            <OnPlatform.Platforms>
                <On Platform="Android">
                    <TapGestureRecognizer Tapped="Header_Tapped" />
                </On>
                <!--<On Platform="WinUI">
                    <TapGestureRecognizer Tapped="Header_Tapped" />
                </On>-->
            </OnPlatform.Platforms>
        </OnPlatform>
    </Border.GestureRecognizers>
</Border>

Un-commenting the WinUI part above makes the NullReferenceException disappear.

Attached the complete reproduction project, which is basically a empty MAUI App project with the XAML definition from above.

GestureRecognizerCrash.zip

Steps to Reproduce

  1. Open the attached project
  2. Build and run the project in Windows

Result: crash with a NullReferenceException

Link to public reproduction project repository

No response

Version with bug

8.0.70 SR7

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.61 SR6.1

Affected platforms

Windows

Affected platform versions

Windows 10.0.19041.0

Did you find any workaround?

Un-commenting the lines in the XAML extract above fixes the crash.

Downgrading both dependencies (maybe one is enough?) below from version 8.0.70 to version 8.0.61 also fix the crash:

  • Microsoft.Maui.Controls
  • Microsoft.Maui.Controls.Compatibility

Relevant log output

Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.View..ctor.__AddItems|15_1(System.Collections.IList newItems)	Unknown
 	Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.View..ctor.AnonymousMethod__15_0(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args)	Unknown
>	System.ObjectModel.dll!System.Collections.ObjectModel.ObservableCollection<Microsoft.Maui.Controls.IGestureRecognizer>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) Line 192	C#
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	System.Private.CoreLib.dll!System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(object obj, System.Span<object> copyOfArgs, System.Reflection.BindingFlags invokeAttr) Line 178	C#
 	System.Private.CoreLib.dll!System.Reflection.MethodBaseInvoker.InvokeWithOneArg(object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object[] parameters, System.Globalization.CultureInfo culture) Line 104	C#
 	Microsoft.Maui.Controls.Xaml.dll!Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.TryAddToProperty(object element, Microsoft.Maui.Controls.Xaml.XmlName propertyName, object value, string xKey, System.Xml.IXmlLineInfo lineInfo, System.IServiceProvider serviceProvider, object rootElement, out System.Exception exception)	Unknown
 	Microsoft.Maui.Controls.Xaml.dll!Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.TrySetPropertyValue(object element, Microsoft.Maui.Controls.Xaml.XmlName propertyName, string xKey, object value, object rootElement, System.Xml.IXmlLineInfo lineInfo, System.IServiceProvider serviceProvider, out System.Exception xpe)	Unknown
 	Microsoft.Maui.Controls.Xaml.dll!Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.SetPropertyValue(object xamlelement, Microsoft.Maui.Controls.Xaml.XmlName propertyName, object value, object rootElement, Microsoft.Maui.Controls.Xaml.INode node, Microsoft.Maui.Controls.Xaml.HydrationContext context, System.Xml.IXmlLineInfo lineInfo)	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.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<GestureRecognizerCrash.MainPage>(GestureRecognizerCrash.MainPage view, System.Type callingType)	Unknown
 	GestureRecognizerCrash.dll!GestureRecognizerCrash.MainPage.InitializeComponent() Line 22	C#
 	GestureRecognizerCrash.dll!GestureRecognizerCrash.MainPage.MainPage() Line 9	C#
 	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) Line 387	C#
 	Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.IApplicationOverrides.Do_Abi_OnLaunched_0(nint thisPtr, nint args) Line 13722	C#
 	[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) Line 13745	C#
 	Microsoft.WinUI.dll!Microsoft.UI.Xaml.Application.Start(Microsoft.UI.Xaml.ApplicationInitializationCallback callback) Line 320	C#
 	GestureRecognizerCrash.dll!GestureRecognizerCrash.WinUI.Program.Main(string[] args) Line 32	C#
@Jean-RobertLaffineur Jean-RobertLaffineur added the t/bug Something isn't working label Sep 24, 2024
Copy link
Contributor

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@jfversluis
Copy link
Member

Would you also be able to test with the latest available .NET MAUI version? 8.0.90, small chance, but maybe we fixed it there already?

@jfversluis jfversluis added area-gestures Gesture types potential-regression This issue described a possible regression on a currently supported version., verification pending labels Sep 24, 2024
@CathyZhu0110 CathyZhu0110 added platform/windows 🪟 s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed i/regression This issue described a confirmed regression on a currently supported version and removed potential-regression This issue described a possible regression on a currently supported version., verification pending labels Sep 25, 2024
@CathyZhu0110
Copy link

CathyZhu0110 commented Sep 25, 2024

This issue has been verified and can repro using Visual Studio 17.12.0 Preview 2.0(8.0.90 & 8.0.70), but not repro on 8.0.61.

@StephaneDelcroix
Copy link
Contributor

there's no default, hence the null ref. but it should no-op, and not fail. Does this happens on release builds as well ?

@StephaneDelcroix StephaneDelcroix self-assigned this Sep 30, 2024
@StephaneDelcroix
Copy link
Contributor

I can confirm this. it fails on both Debug ans Release

StephaneDelcroix added a commit that referenced this issue Sep 30, 2024
StephaneDelcroix added a commit that referenced this issue Sep 30, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in MAUI SDK Ongoing Sep 30, 2024
@PureWeen PureWeen modified the milestones: .NET 8 SR9, .NET 8 SR9.2 Oct 1, 2024
github-actions bot pushed a commit that referenced this issue Oct 1, 2024
rmarinho pushed a commit that referenced this issue Oct 1, 2024
rmarinho pushed a commit that referenced this issue Oct 16, 2024
rmarinho pushed a commit that referenced this issue Oct 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-gestures Gesture types fixed-in-8.0.92 i/regression This issue described a confirmed regression on a currently supported version platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

6 participants