{"record":{"id":"01ec297bc45d7876","repo":"dotnet/wpf","slug":"sr-doesnotsupportmultipleselection-windowscalendar","errorCode":null,"errorMessage":"SR.DoesNotSupportMultipleSelection","messagePattern":"SR\\.DoesNotSupportMultipleSelection","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/WindowsCalendar.cs","lineNumber":3679,"sourceCode":"                    // Make sure that the control is enabled\n                    if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n                    {\n                        throw new ElementNotEnabledException();\n                    }\n\n                    ISelectionItemProvider selProvider = (ISelectionItemProvider) this;\n\n                    // check if item already selected\n                    if (selProvider.IsSelected)\n                    {\n                        return;\n                    }\n\n                    // if does not support multiple selection\n                    // and other element(not us) is already selected return false\n                    if (!WindowsCalendar.IsMultiSelect(_hwnd))\n                    {\n                        throw new InvalidOperationException(SR.DoesNotSupportMultipleSelection);\n                    }\n\n                    DateTime [] dateSelection =\n                        WindowsCalendar.CreateDateTimeFromSystemTime (\n                            WindowsCalendar.GetRawValue (_hwnd, WindowsCalendar.CalendarData.Selection));\n                    DateTime itemDateTime = GetDateTime();\n\n                    // Valid grid item but no date int the cell, before beginning or end of the week\n                    if (itemDateTime == DateTime.MinValue)\n                    {\n                        throw new InvalidOperationException(SR.OperationCannotBePerformed);\n                    }\n\n                    // The day can only be added if it \n                    TimeSpan ts = dateSelection[0] - itemDateTime;\n\n                    if (ts.Days == 1)\n                    {","sourceCodeStart":3661,"sourceCodeEnd":3697,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/WindowsCalendar.cs#L3661-L3697","documentation":"WindowsCalendar.CalendarDay's ISelectionItemProvider.AddToSelection() throws InvalidOperationException(SR.DoesNotSupportMultipleSelection) when WindowsCalendar.IsMultiSelect(_hwnd) is false. A single-selection MonthCalendar cannot add a second date to the selection, so AddToSelection is invalid.","triggerScenarios":"Calling AddToSelection() on a day element when the native calendar is single-select (no MCS_MULTISELECT style / IsMultiSelect false) and another date is or would be selected.","commonSituations":"UIA clients using generic multi-selection logic on the standard (single-select) MonthCalendar; scripts assuming SelectionItem.AddToSelection is always supported.","solutions":["Check whether the calendar supports multi-select before calling AddToSelection (e.g. query the control style or SelectionPattern.CanSelectMultiple).","Use Select() instead of AddToSelection() on single-selection calendars.","Enable multi-select on the underlying control (MSMultiSelect style / MaxSelectionCount) if multiple dates are required.","Catch InvalidOperationException and fall back to Select() to replace the current selection."],"exampleFix":"// before\nselectionItemPattern.AddToSelection();\n// after\nif (selectionPattern.Current.CanSelectMultiple)\n{\n    selectionItemPattern.AddToSelection();\n}\nelse\n{\n    selectionItemPattern.Select();\n}","handlingStrategy":"validation","validationCode":"if (selectionPattern.Current.CanSelectMultiple) { selectionItemPattern.AddToSelection(); } else { selectionItemPattern.Select(); }","typeGuard":null,"tryCatchPattern":"try { selectionItemPattern.AddToSelection(); } catch (InvalidOperationException) { selectionItemPattern.Select(); /* single-select fallback */ }","preventionTips":["Check CanSelectMultiple before AddToSelection","Use Select() on single-selection calendars","Enable multi-select on the native control only if multi-date selection is truly required"],"tags":["uiautomation","selection","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}