[BUG] Using IsStringNullOrEmptyConverter to assign AutomationProperties.IsInAccessibleTree causes ArgumentException
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Did you read the “Reporting a bug” section on Contributing file?
- I have read the “Reporting a bug” section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
When using converters from the Maui.CommunityToolkit (in particular, when using the IsStringNotNullOrEmpty
converter when trying to set AutomationProperties.IsInAccessibleTree
, an ArgumentException
is thrown and you are unable to load the page where the converter is used.
I have primarily tested/encountered this issue on iOS and Android, however the attached repo will also show the issue on Windows apps.
See attached StackTrace:
System.ArgumentException: targetType needs to be assignable from System.Boolean. (Parameter 'targetType')
at CommunityToolkit.Maui.Extensions.ValueConverterExtension.ValidateTargetType[Boolean](Type targetType) in /_/src/CommunityToolkit.Maui/Extensions/ValueConverterExtension.shared.cs:line 65
at CommunityToolkit.Maui.Converters.BaseConverter`2[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Boolean, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].CommunityToolkit.Maui.Converters.ICommunityToolkitValueConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture) in /_/src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs:line 165
at CommunityToolkit.Maui.Converters.ICommunityToolkitValueConverter.Microsoft.Maui.Controls.IValueConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture) in /_/src/CommunityToolkit.Maui/Converters/ICommunityToolkitValueConverter.shared.cs:line 52
at Microsoft.Maui.Controls.Binding.GetSourceValue(Object value, Type targetPropertyType) in D:\a\_work\1\s\src\Controls\src\Core\Binding.cs:line 299
at Microsoft.Maui.Controls.BindingExpression.ApplyCore(Object sourceObject, BindableObject target, BindableProperty property, Boolean fromTarget) in D:\a\_work\1\s\src\Controls\src\Core\BindingExpression.cs:line 149
at Microsoft.Maui.Controls.BindingExpression.Apply(Object sourceObject, BindableObject target, BindableProperty property) in D:\a\_work\1\s\src\Controls\src\Core\BindingExpression.cs:line 75
at Microsoft.Maui.Controls.Binding.Apply(Object context, BindableObject bindObj, BindableProperty targetProperty, Boolean fromBindingContextChanged) in D:\a\_work\1\s\src\Controls\src\Core\Binding.cs:line 136
at Microsoft.Maui.Controls.BindableObject.SetBinding(BindableProperty targetProperty, BindingBase binding, Boolean fromStyle) in D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:line 229
at Microsoft.Maui.Controls.BindableObject.SetBinding(BindableProperty targetProperty, BindingBase binding) in D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:line 205
at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.TrySetBinding(Object element, BindableProperty property, String localName, Object value, IXmlLineInfo lineInfo, BindingBase& binding, Exception& exception) in D:\a\_work\1\s\src\Controls\src\Xaml\ApplyPropertiesVisitor.cs:line 539
at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.TrySetPropertyValue(Object element, XmlName propertyName, String xKey, Object value, Object rootElement, IXmlLineInfo lineInfo, IServiceProvider serviceProvider, Exception& xpe) in D:\a\_work\1\s\src\Controls\src\Xaml\ApplyPropertiesVisitor.cs:line 409
at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.SetPropertyValue(Object xamlelement, XmlName propertyName, Object value, Object rootElement, INode node, HydrationContext context, IXmlLineInfo lineInfo) in D:\a\_work\1\s\src\Controls\src\Xaml\ApplyPropertiesVisitor.cs:line 373
at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.Visit(ElementNode node, INode parentNode) in D:\a\_work\1\s\src\Controls\src\Xaml\ApplyPropertiesVisitor.cs:line 120
at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode) in D:\a\_work\1\s\src\Controls\src\Xaml\XamlNode.cs:line 159
at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode) in D:\a\_work\1\s\src\Controls\src\Xaml\XamlNode.cs:line 153
at Microsoft.Maui.Controls.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode) in D:\a\_work\1\s\src\Controls\src\Xaml\XamlNode.cs:line 212
at Microsoft.Maui.Controls.Xaml.XamlLoader.Visit(RootNode rootnode, HydrationContext visitorContext, Boolean useDesignProperties) in D:\a\_work\1\s\src\Controls\src\Xaml\XamlLoader.cs:line 210
at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Assembly rootAssembly, Boolean useDesignProperties) in D:\a\_work\1\s\src\Controls\src\Xaml\XamlLoader.cs:line 78
at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Boolean useDesignProperties) in D:\a\_work\1\s\src\Controls\src\Xaml\XamlLoader.cs:line 53
at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, Type callingType) in D:\a\_work\1\s\src\Controls\src\Xaml\XamlLoader.cs:line 49
at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml[MainPage](MainPage view, Type callingType) in D:\a\_work\1\s\src\Controls\src\Xaml\ViewExtensions.cs:line 37
at ConverterBinding.MainPage.InitializeComponent() in ConverterBinding\ConverterBinding\Microsoft.Maui.Controls.SourceGen\Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator\MainPage.xaml.sg.cs:line 26
at ConverterBinding.MainPage..ctor() in ConverterBinding\ConverterBinding\MainPage.xaml.cs:line 9
at ConverterBinding.App..ctor() in ConverterBinding\ConverterBinding\App.xaml.cs:line 9
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite callSite, RuntimeResolverContext argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType)
at System.Collections.Concurrent.ConcurrentDictionary`2[[System.Type, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Func`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetOrAdd(Type key, Func`2 valueFactory)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType) in D:\a\_work\1\s\src\Core\src\MauiContext.cs:line 68
at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType) in D:\a\_work\1\s\src\Core\src\MauiContext.cs:line 68
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[IApplication](IServiceProvider provider)
at Microsoft.Maui.MauiApplication.OnCreate() in D:\a\_work\1\s\src\Core\src\Platform\Android\MauiApplication.cs:line 37
at Android.App.Application.n_OnCreate(IntPtr jnienv, IntPtr native__this) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.App.Application.cs:line 1072
at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 22
Expected Behavior
The converter should correctly return true
or false
based on the string
it is converting, and the AutomationProperties.IsInAccessibleTree
property should be set.
Steps To Reproduce
- Open and run solution in debug mode from provided repo
- The app will throw an exception
- In MainPage.xaml, swap out the current StackLayout for the commented StackLayout to observe the app loading successfully without issue
Link to public reproduction project repository
https://github.com/BruceTheBrick/ConverterBinding
Environment
- .NET MAUI CommunityToolkit: 5.2.0
- OS: Windows 11, Windows 10
- .NET MAUI: 7.0.92/7.0.100
Anything else?
No response
Issue Analytics
- State:
- Created 2 months ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
Automation Properties in Xamarin.Forms
In this article · AutomationProperties.IsInAccessibleTree – indicates whether the element is available to an accessible application.
Read more >Unable to assign Accessibility using Automation properties ...
I need to locate my Android elements written in Xamarin forms on Appium for automation testing. I have the following structure of code:....
Read more >I dont understand the behavior of the AutomationProperties ...
I am testing the AutomationProperties class to make the app accessible. But I don't understand why the HelpText or Name properties that are...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You may be onto something there. I have noticed that using the same
IsStringNotNullOrEmptyConverter
on a different property, say for exampleIsVisible
does not seem to throw the same exception. I will check to see if creating a bindablebool?
property and using this converter there will cause the same problems.Oh
AutomationProperties.IsInAccessibleTree
is abool?
I bet it’s the nullability that is causing the validation to fail