dotnet/wpf · error · ArgumentException

SR.PropertyNotSupported

Error message

SR.PropertyNotSupported

What it means

CalendarAutomationPeer.FindItemByProperty only supports searching by null propertyId (first item), ControlTypeProperty, or NameProperty. Any other AutomationProperty id reaches the final else branch and throws ArgumentException(SR.PropertyNotSupported), per the IItemContainerProvider contract that unsupported search properties are rejected.

Solutions

  1. Restrict searches to AutomationElementIdentifiers.ControlTypeProperty, NameProperty, or null (propertyId == 0).
  2. To filter by other attributes (e.g. AutomationId), enumerate the calendar's child automation peers and filter in client code.
  3. Catch ArgumentException around FindItemByProperty and fall back to manual child enumeration.
  4. Use client-side UIA FindFirst with TreeWalker conditions instead of the provider-level method for arbitrary properties.

Example fix

// before
var item = peer.FindItemByProperty(null, AutomationElement.AutomationIdProperty, "day1"); // not supported
// after
var item = peer.FindItemByProperty(null, AutomationElement.NameProperty, "Monday, May 1, 2024");
Defensive patterns

Strategy: validation

Validate before calling

if (!(property == null || property == AutomationElement.NameProperty || property == AutomationElement.ControlTypeProperty))
    throw new ArgumentException("Calendar FindItemByProperty supports only Name, ControlType, or null.");

Try / catch

try { var item = peer.FindItemByProperty(start, property, value); }
catch (ArgumentException)
{
    // enumerate child peers and filter manually
}

Prevention

When it happens

Trigger: Calling FindItemByProperty(startAfter, property, value) with a property such as AutomationIdProperty, HelpTextProperty, or any non-ControlType/non-Name AutomationProperty.

Common situations: Generic automation search helpers passing arbitrary property ids; migrating code that assumed all AutomationElement properties were searchable; test frameworks filtering calendar items by AutomationId.

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/cb7c6d7149014b14. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/CalendarAutomationPeer.cs:528

                    throw new InvalidOperationException(SR.CalendarNamePropertyValueNotValid);
                }

                currentMode = (startAfterDatePeer != null) ? startAfterDatePeer.ButtonMode : OwningCalendar.DisplayMode;
            }
            else if (propertyId == 0 || propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id)
            {
                // propertyId = 0 returns the button next to the startAfter or the DisplayDate if startAfter is null
                // All items here are buttons, so same behaviour as propertyId = 0
                if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id && (int)value != ControlType.Button.Id)
                {
                    return null;
                }
                currentMode = (startAfterDatePeer != null) ? startAfterDatePeer.ButtonMode : OwningCalendar.DisplayMode;
                nextDate = GetNextDate(startAfterDatePeer, currentMode);
            }
            else
            {
                throw new ArgumentException(SR.PropertyNotSupported);
            }

            if (nextDate.HasValue)
            {
                AutomationPeer nextPeer = GetOrCreateDateTimeAutomationPeer(nextDate.Value, currentMode);
                if (nextPeer != null)
                {
                    return ProviderFromPeer(nextPeer);
                }
            }
            return null;
        }

        private DateTime? GetNextDate(DateTimeAutomationPeer currentDatePeer, CalendarMode currentMode)
        {
            DateTime? nextDate = null;

            DateTime startDate = (currentDatePeer != null) ? currentDatePeer.Date : OwningCalendar.DisplayDate;

View on GitHub (pinned to 81131a70a4)