{"record":{"id":"2ce655b90656392c","repo":"dotnet/wpf","slug":"sr-inavalidstartitem","errorCode":null,"errorMessage":"SR.InavalidStartItem","messagePattern":"SR\\.InavalidStartItem","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/CalendarAutomationPeer.cs","lineNumber":486,"sourceCode":"\n            return null;\n        }\n\n        #endregion ISelectionProvider\n\n        #region IItemContainerProvider\n        \n        IRawElementProviderSimple IItemContainerProvider.FindItemByProperty(IRawElementProviderSimple startAfterProvider, int propertyId, object value)\n        {\n            DateTimeAutomationPeer startAfterDatePeer = null;\n            \n            if (startAfterProvider != null)\n            {\n                startAfterDatePeer = PeerFromProvider(startAfterProvider) as DateTimeAutomationPeer;\n                // if provider is not null, peer must exist\n                if (startAfterDatePeer == null)\n                {\n                    throw new InvalidOperationException(SR.InavalidStartItem);\n                }\n            }\n\n            DateTime? nextDate = null;\n            CalendarMode currentMode = 0;\n\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                {","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/CalendarAutomationPeer.cs#L468-L504","documentation":"CalendarAutomationPeer.FindItemByProperty throws InvalidOperationException(SR.InavalidStartItem) when the IItemContainerProvider.FindItemByProperty startAfter provider is supplied but cannot be resolved to a DateTimeAutomationPeer belonging to this calendar. The contract requires the start item, if given, to be a child item of this container; anything else is invalid.","triggerScenarios":"Calling FindItemByProperty(IRawElementProviderSimple startAfter, ...) with a provider that is not one of this Calendar's DateTimeAutomationPeer items — e.g. a provider from another control, a released/stale peer, or a non-date element inside the calendar.","commonSituations":"UIA clients caching provider references across calendar rebinding or mode changes so old date peers become stale; passing a provider from a different Calendar instance; frameworks passing the container itself as the start item.","solutions":["Pass null as startAfter to search from the beginning, or pass only providers obtained from this calendar's FindItemByProperty/children.","Re-acquire the start item provider right before the call instead of caching it across UI updates.","Verify the start provider belongs to the same Calendar instance whose peer you are calling.","Catch InvalidOperationException and restart the search with startAfter = null."],"exampleFix":"// before\nvar next = containerPeer.FindItemByProperty(staleProvider, property, value); // stale peer\n// after\nvar next = containerPeer.FindItemByProperty(null, property, value); // search from start","handlingStrategy":"validation","validationCode":"// only pass providers that are live date children of this calendar\nif (startAfterProvider != null && !belongsToThisCalendar(startAfterProvider))\n    startAfterProvider = null; // search from the beginning instead","typeGuard":null,"tryCatchPattern":"try { var item = peer.FindItemByProperty(startAfter, prop, value); }\ncatch (InvalidOperationException)\n{\n    var item = peer.FindItemByProperty(null, prop, value); // restart from beginning\n}","preventionTips":["Pass null startAfter unless you hold a live child provider.","Re-acquire start providers after any calendar rebinding.","Never share providers across different Calendar instances."],"tags":["wpf","ui-automation","calendar","item-container","invalid-argument"],"backgroundTag":"invalid-argument-value","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"}