dotnet/wpf · error · ArgumentException

SR.PropertyNotSupported

Error message

SR.PropertyNotSupported

What it means

DataGridItemAutomationPeer.FindItemByProperty throws ArgumentException when propertyId is non-zero and is not one of the properties the control supports for UIA item searches. The library validates the property up front rather than silently returning no results.

Solutions

  1. Query SelectorAutomationPeer.IsPropertySupportedByControlForFindItemInternal(propertyId) before the call.
  2. Pass 0 for propertyId to search without property filtering, then filter manually.
  3. Catch ArgumentException and retry with propertyId = 0.
  4. Use only documented automation properties (e.g. NameProperty) supported for FindItemByProperty on this control.

Example fix

// before
rowPeer.FindItemByProperty(null, SelectionItemPattern.Pattern.Id, null); // unsupported
// after
int propertyId = AutomationElement.NameProperty.Id;
var item = SelectorAutomationPeer.IsPropertySupportedByControlForFindItemInternal(propertyId)
    ? rowPeer.FindItemByProperty(null, propertyId, null)
    : rowPeer.FindItemByProperty(null, 0, null);
Defensive patterns

Strategy: validation

Validate before calling

if (propertyId != 0 && !SelectorAutomationPeer.IsPropertySupportedByControlForFindItemInternal(propertyId))
    propertyId = 0;

Try / catch

try { return peer.FindItemByProperty(start, propertyId, value); }
catch (ArgumentException) { return peer.FindItemByProperty(start, 0, value); }

Prevention

When it happens

Trigger: Calling FindItemByProperty on a DataGrid row peer with a propertyId that is not supported by SelectorAutomationPeer.IsPropertySupportedByControlForFindItemInternal (e.g. an automation property unrelated to item search).

Common situations: UIA client code written against a different control type (which supports more properties) reused against DataGrid rows; hard-coded property IDs from other frameworks.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/089bfec9d75f028c. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridItemAutomationPeer.cs:135

                    }
                }
            }

            return base.GetPeerFromPointCore(point);
        }

        #endregion

        #region IItemContainerProvider
        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 (!SelectorAutomationPeer.IsPropertySupportedByControlForFindItemInternal(propertyId))
                {
                    throw new ArgumentException(SR.PropertyNotSupported);
                }
            }


            IList<DataGridColumn> columns = OwningDataGrid.Columns;

            if (columns != null && columns.Count > 0)
            {
                DataGridCellItemAutomationPeer startAfterItem = null;
                if (startAfter != null)
                {
                    // get the peer corresponding to this provider
                    startAfterItem = PeerFromProvider(startAfter) as DataGridCellItemAutomationPeer;
                }

                // startIndex refers to the index of the item just after startAfterItem
                int startIndex = 0;
                if (startAfterItem != null)

View on GitHub (pinned to 81131a70a4)