dotnet/wpf · error · ArgumentException
SR.PropertyNotSupported
Error message
SR.PropertyNotSupported
What it means
ItemsControlAutomationPeer.FindItemByProperty/GetChildrenCore path validates the propertyId passed by the UIA client: if a non-zero property id is given and it is not one of the properties supported by this control for find-item operations, it throws ArgumentException(SR.PropertyNotSupported). This tells the client the requested property cannot be used as a filter.
Solutions
- Pass only properties supported for find-item (typically AutomationIdProperty or NameProperty) or null/0 to match any property.
- Use FindFirst/TreeWalker with manual property comparison instead of FindItemByProperty for unsupported properties.
- Catch ArgumentException and fall back to enumerating children and comparing the property yourself.
Example fix
// before container.FindItemByProperty(null, SelectionItemPattern.IsSelectedProperty, true); // unsupported // after var item = container.FindItemByProperty(null, AutomationElement.AutomationIdProperty, targetId);
Defensive patterns
Strategy: validation
Validate before calling
if (propertyId != 0 && propertyId != AutomationElement.AutomationIdProperty.Id && propertyId != AutomationElement.NameProperty.Id) throwSkipFind();
Type guard
bool IsSupportedFindProperty(int id) => id == 0 || id == AutomationElement.AutomationIdProperty.Id || id == AutomationElement.NameProperty.Id;
Try / catch
try { container.FindItemByProperty(start, prop, value); } catch (ArgumentException) { /* enumerate children manually */ } Prevention
- Only pass AutomationIdProperty or NameProperty to FindItemByProperty.
- Pass null property to match all items.
- Fall back to manual TreeWalker enumeration for other properties.
When it happens
Trigger: Calling UI FindItemByProperty (IItemContainerProvider.FindItemByProperty) with a propertyId that the ItemsControl does not support for filtering (only AutomationIdProperty, NameProperty, etc. are typically supported).
Common situations: UIA clients using IItemContainerProvider to search items by a property like IsSelectedProperty or a custom property; generic test frameworks passing arbitrary AutomationProperty ids.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.CalendarNamePropertyValueNotValid
- SR.InavalidStartItem
- SR.InavalidStartItem
- Animation_ChildMustBeKeyFrame
- Animation_DependencyPropertyIsNotAnimatable
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/b5a6e85f29dc5eb0.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemsControlAutomationPeer.cs:235
ItemsControl owner = this.Owner as ItemsControl;
ItemCollection items = owner.Items;
if(items != null)
{
if(GetPeerFromWeakRefStorage(itemPeer.Item) == null)
WeakRefElementProxyStorage[itemPeer.Item] = wr;
}
}
///
IRawElementProviderSimple IItemContainerProvider.FindItemByProperty(IRawElementProviderSimple startAfter, int propertyId, object value)
{
ResetChildrenCache();
// Checks if propertyId is valid else throws ArgumentException to notify it as invalid argument is being passed
if (propertyId != 0)
{
if (!IsPropertySupportedByControlForFindItem(propertyId))
{
throw new ArgumentException(SR.PropertyNotSupported);
}
}
ItemsControl owner = (ItemsControl)Owner;
ItemCollection items = null;
if(owner != null)
items = owner.Items;
if (items != null && items.Count > 0)
{
ItemAutomationPeer startAfterItem = null;
if (startAfter != null)
{
// get the peer corresponding to this provider
startAfterItem = PeerFromProvider(startAfter) as ItemAutomationPeer;
if(startAfterItem == null)
return null;View on GitHub (pinned to 81131a70a4)