MicrosoftDocs / CommunityToolkit

The Official Docs for the Community Toolkits
https://learn.microsoft.com/dotnet/communitytoolkit
Creative Commons Attribution 4.0 International
109 stars 90 forks source link

EventToCommandBehavior broken in 8.3 #460

Closed guerillacodester closed 3 weeks ago

guerillacodester commented 1 month ago

Type of issue

The latest 8.3 update breaks EventToCommandBehavior. My workaround is to revert to Version 8.2.2

Description

[Enter feedback here] No issues whatsoever with version update 8.2.2, but for the latest update, an exception is raised rendering it unusable. This code works fine for 8.22, but for 8.3 it raises an exception pasted below.

        <Button x:DataType="viewModels:MainPageViewModel"
            x:Name="CounterBtn"
            Text="Click me" 
            SemanticProperties.Hint="Counts the number of times you click"
            HorizontalOptions="Fill">
            <Button.Behaviors>
                <toolkit:EventToCommandBehavior
                    EventName="Clicked"
                    Command="{Binding ClickedCommand}">
                </toolkit:EventToCommandBehavior>
            </Button.Behaviors>
        </Button>

Version update 8.3 produces this exception:

System.Reflection.TargetInvocationException HResult=0x80131604 Message=Exception has been thrown by the target of an invocation. Source=System.Private.CoreLib StackTrace: at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Microsoft.Maui.Controls.BindingExpression.BindingExpressionPart.TryGetValue(Object source, Object& value) at Microsoft.Maui.Controls.BindingExpression.ApplyCore(Object sourceObject, BindableObject target, BindableProperty property, Boolean fromTarget, SetterSpecificity specificity) at Microsoft.Maui.Controls.BindingExpression.Apply(Object sourceObject, BindableObject target, BindableProperty property, SetterSpecificity specificity) at Microsoft.Maui.Controls.Binding.Apply(Object context, BindableObject bindObj, BindableProperty targetProperty, Boolean fromBindingContextChanged, SetterSpecificity specificity) at Microsoft.Maui.Controls.BindableObject.ApplyBindings(Boolean skipBindingContext, Boolean fromBindingContextChanged) at Microsoft.Maui.Controls.BindableObject.BindingContextPropertyChanged(BindableObject bindable, Object oldvalue, Object newvalue) at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent) at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) at Microsoft.Maui.Controls.BindingExpression.ApplyCore(Object sourceObject, BindableObject target, BindableProperty property, Boolean fromTarget, SetterSpecificity specificity) at Microsoft.Maui.Controls.BindingExpression.Apply(Boolean fromTarget) at Microsoft.Maui.Controls.BindingExpression.BindingExpressionPart.b50_0() at Microsoft.Maui.Controls.DispatcherExtensions.DispatchIfRequired(IDispatcher dispatcher, Action action) at Microsoft.Maui.Controls.BindingExpression.BindingExpressionPart.PropertyChanged(Object sender, PropertyChangedEventArgs args) at Microsoft.Maui.Controls.BindingExpression.WeakPropertyChangedProxy.OnPropertyChanged(Object sender, PropertyChangedEventArgs e) at Microsoft.Maui.Controls.BindingExpression.WeakPropertyChangedProxy.OnBCChanged(Object sender, EventArgs e) at Microsoft.Maui.Controls.BindableObject.OnBindingContextChanged() at Microsoft.Maui.Controls.Element.OnBindingContextChanged() at Microsoft.Maui.Controls.VisualElement.OnBindingContextChanged() at Microsoft.Maui.Controls.View.OnBindingContextChanged() at Microsoft.Maui.Controls.Button.OnBindingContextChanged() at Microsoft.Maui.Controls.BindableObject.SetInheritedBindingContext(BindableObject bindable, Object value) at Microsoft.Maui.Controls.Element.SetChildInheritedBindingContext(Element child, Object context) at Microsoft.Maui.Controls.Element.b__89_0(BindableObject child, Object bc) at Microsoft.Maui.Controls.BindableObjectExtensions.PropagateBindingContext[T](BindableObject self, IEnumerable1 children, Action2 setChildBindingContext) at Microsoft.Maui.Controls.Element.OnBindingContextChanged() at Microsoft.Maui.Controls.VisualElement.OnBindingContextChanged() at Microsoft.Maui.Controls.View.OnBindingContextChanged() at Microsoft.Maui.Controls.BindableObject.SetInheritedBindingContext(BindableObject bindable, Object value) at Microsoft.Maui.Controls.Element.SetChildInheritedBindingContext(Element child, Object context) at Microsoft.Maui.Controls.Element.b89_0(BindableObject child, Object bc) at Microsoft.Maui.Controls.BindableObjectExtensions.PropagateBindingContext[T](BindableObject self, IEnumerable1 children, Action2 setChildBindingContext) at Microsoft.Maui.Controls.Element.OnBindingContextChanged() at Microsoft.Maui.Controls.VisualElement.OnBindingContextChanged() at Microsoft.Maui.Controls.View.OnBindingContextChanged() at Microsoft.Maui.Controls.BindableObject.SetInheritedBindingContext(BindableObject bindable, Object value) at Microsoft.Maui.Controls.Element.SetChildInheritedBindingContext(Element child, Object context) at Microsoft.Maui.Controls.TemplatedPage.SetChildInheritedBindingContext(Element child, Object context) at Microsoft.Maui.Controls.Element.b89_0(BindableObject child, Object bc) at Microsoft.Maui.Controls.BindableObjectExtensions.PropagateBindingContext[T](BindableObject self, IEnumerable1 children, Action2 setChildBindingContext) at Microsoft.Maui.Controls.Element.OnBindingContextChanged() at Microsoft.Maui.Controls.VisualElement.OnBindingContextChanged() at Microsoft.Maui.Controls.Page.OnBindingContextChanged() at Microsoft.Maui.Controls.ContentPage.OnBindingContextChanged() at Microsoft.Maui.Controls.BindableObject.BindingContextPropertyChanged(BindableObject bindable, Object oldvalue, Object newvalue) at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent) at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value) at Microsoft.Maui.Controls.BindableObject.set_BindingContext(Object value) at DeviceCommander.MauiProgram.<>c.b0_1(IServiceProvider s) in E:\Source Code\Practice\MAUI\Full MAUI Course\DeviceCommander\MauiProgram.cs:line 27 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(ServiceIdentifier serviceIdentifier) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType) at Microsoft.Maui.Controls.ShellContent.<>cDisplayClass19_0.b__0() at Microsoft.Maui.Controls.ElementTemplate.CreateContent() at Microsoft.Maui.Controls.Internals.DataTemplateExtensions.CreateContent(DataTemplate self, Object item, BindableObject container) at Microsoft.Maui.Controls.ShellContent.Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent() at Microsoft.Maui.Controls.Handlers.ShellContentHandler.CreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler2.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.ElementExtensions.ToPlatform(IElement view, IMauiContext context) at Microsoft.Maui.Controls.Handlers.ShellSectionHandler.SyncNavigationStack(Boolean animated, NavigationRequestedEventArgs e) at Microsoft.Maui.Controls.Handlers.ShellSectionHandler.MapCurrentItem(ShellSectionHandler handler, ShellSection item) at Microsoft.Maui.PropertyMapper2.<>cDisplayClass5_0.b0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Controls.Handlers.ShellSectionHandler.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.Controls.Handlers.ShellItemHandler.UpdateCurrentItem() at Microsoft.Maui.Controls.Handlers.ShellItemHandler.MapCurrentItem(ShellItemHandler handler, ShellItem item) at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0.b0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Controls.Handlers.ShellItemHandler.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.Controls.Platform.ShellView.CreateShellItemView() at Microsoft.Maui.Controls.Platform.ShellView.SwitchShellItem(ShellItem newItem, Boolean animate) at Microsoft.Maui.Controls.Handlers.ShellHandler.MapCurrentItem(ShellHandler handler, Shell view) at Microsoft.Maui.PropertyMapper2.<>c__DisplayClass5_0.<Add>b__0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Handlers.ViewHandler2.SetVirtualView(IView view) at Microsoft.Maui.Controls.Handlers.ShellHandler.SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler2.SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) at Microsoft.Maui.Handlers.WindowHandler.MapContent(IWindowHandler handler, IWindow window) at Microsoft.Maui.PropertyMapper2.<>c__DisplayClass5_0.b__0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) 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.SetHandler(IWinRTObject nativeElement, IElement element, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.SetWindowHandler(Window platformWindow, IWindow window, IMauiContext context) at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Application platformApplication, IApplication application, OpenWindowRequest args) at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Application platformApplication, IApplication application, LaunchActivatedEventArgs args) at Microsoft.Maui.MauiWinUIApplication.OnLaunched(LaunchActivatedEventArgs args) at Microsoft.UI.Xaml.Application.Microsoft.UI.Xaml.IApplicationOverrides.OnLaunched(LaunchActivatedEventArgs args) at ABI.Microsoft.UI.Xaml.IApplicationOverrides.Do_Abi_OnLaunched_0(IntPtr thisPtr, IntPtr args)

This exception was originally thrown at this call stack: [External Code]

Inner Exception 1: TypeInitializationException: The type initializer for '' threw an exception.

Inner Exception 2: FileNotFoundException: Could not load file or assembly 'WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709'. The system cannot find the file specified.

Page URL

https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/behaviors/event-to-command-behavior

Content source URL

https://github.com/MicrosoftDocs/CommunityToolkit/blob/main/docs/maui/behaviors/event-to-command-behavior.md

Document Version Independent Id

58641c2f-ab81-656a-e724-ebd12c35d732

Article author

@CliffAgius

Metadata

bijington commented 3 weeks ago

Can you please raise this on the code repository over at: https://github.com/CommunityToolkit/Maui

I will close this for now because this repository is just for the documentation