{"record":{"id":"25d42312edf7b2a6","repo":"dotnet/wpf","slug":"sr-calendarnamepropertyvaluenotvalid","errorCode":null,"errorMessage":"SR.CalendarNamePropertyValueNotValid","messagePattern":"SR\\.CalendarNamePropertyValueNotValid","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/CalendarAutomationPeer.cs","lineNumber":510,"sourceCode":"\n            if( propertyId == SelectionItemPatternIdentifiers.IsSelectedProperty.Id)\n            {\n                currentMode = CalendarMode.Month;\n                nextDate = GetNextSelectedDate(startAfterDatePeer, (bool)value);\n            }\n            else if (propertyId == AutomationElementIdentifiers.NameProperty.Id)\n            {\n                // finds the button for the given DateTime\n                DateTimeFormatInfo format = DateTimeHelper.GetCurrentDateFormat();\n                DateTime parsedDate;\n                if (DateTime.TryParse((value as string), format, System.Globalization.DateTimeStyles.None, out parsedDate))\n                {\n                    nextDate = parsedDate;\n                }\n\n                if( !nextDate.HasValue || (startAfterDatePeer != null && nextDate <= startAfterDatePeer.Date) )\n                {\n                    throw new InvalidOperationException(SR.CalendarNamePropertyValueNotValid);\n                }\n\n                currentMode = (startAfterDatePeer != null) ? startAfterDatePeer.ButtonMode : OwningCalendar.DisplayMode;\n            }\n            else if (propertyId == 0 || propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id)\n            {\n                // propertyId = 0 returns the button next to the startAfter or the DisplayDate if startAfter is null\n                // All items here are buttons, so same behaviour as propertyId = 0\n                if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id && (int)value != ControlType.Button.Id)\n                {\n                    return null;\n                }\n                currentMode = (startAfterDatePeer != null) ? startAfterDatePeer.ButtonMode : OwningCalendar.DisplayMode;\n                nextDate = GetNextDate(startAfterDatePeer, currentMode);\n            }\n            else\n            {\n                throw new ArgumentException(SR.PropertyNotSupported);","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/CalendarAutomationPeer.cs#L492-L528","documentation":"CalendarAutomationPeer.FindItemByProperty, when searching by the Name property, parses the start item's Name as a date; if parsing yields no valid DateTime, or the parsed date is not strictly after the start item's date, it throws InvalidOperationException(SR.CalendarNamePropertyValueNotValid). A calendar day's automation Name must be a parseable date string later than the start item.","triggerScenarios":"Calling FindItemByProperty with propertyId == AutomationElementIdentifiers.NamePropertyId where the start item's Name cannot be parsed as a date (custom/localized Name strings) or parses to a date equal to or earlier than the start item's date.","commonSituations":"Applications that override DateTimeAutomationPeer/NameProperty for accessibility, breaking the date parser; culture mismatches so date strings don't parse; automation expecting the default name format on a modified Calendar.","solutions":["Do not override the automation Name of calendar day items; keep the default date-format Name.","If Name overriding is required, search by a different supported property or avoid FindItemByProperty with NamePropertyId.","Catch InvalidOperationException and fall back to enumerating the calendar's child items manually.","Only use supported property ids (Name, ControlType, or 0) and verify the start item's Name parses under the current culture."],"exampleFix":"// before\nvar item = peer.FindItemByProperty(start, AutomationElement.NameProperty, customName); // not a parseable date\n// after\nvar item = peer.FindItemByProperty(start, AutomationElement.NameProperty, defaultDateName); // standard parseable date name","handlingStrategy":"validation","validationCode":"if (!DateTime.TryParse(startItemName, out _))\n    throw new InvalidOperationException(\"Start item Name is not a parseable date; FindItemByProperty(Name) cannot run.\");","typeGuard":"bool IsParseableDateName(string name) => DateTime.TryParse(name, out _);","tryCatchPattern":"try { var item = peer.FindItemByProperty(start, AutomationElement.NameProperty, value); }\ncatch (InvalidOperationException)\n{\n    // fall back to manual child enumeration\n}","preventionTips":["Keep default date-format automation Names on calendar day items.","Only search with NameProperty, ControlTypeProperty, or null.","Account for culture when day Names are generated."],"tags":["wpf","ui-automation","calendar","date-parsing","invalid-argument"],"backgroundTag":"invalid-argument-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}