dotnet/wpf · warning · InvalidOperationException
SR.DoesNotSupportMultipleSelection
Error message
SR.DoesNotSupportMultipleSelection
What it means
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.
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.
Example fix
// before
selectionItemPattern.AddToSelection();
// after
if (selectionPattern.Current.CanSelectMultiple)
{
selectionItemPattern.AddToSelection();
}
else
{
selectionItemPattern.Select();
} Defensive patterns
Strategy: validation
Validate before calling
if (selectionPattern.Current.CanSelectMultiple) { selectionItemPattern.AddToSelection(); } else { selectionItemPattern.Select(); } Try / catch
try { selectionItemPattern.AddToSelection(); } catch (InvalidOperationException) { selectionItemPattern.Select(); /* single-select fallback */ } Prevention
- 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
When it happens
Trigger: 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.
Common situations: UIA clients using generic multi-selection logic on the standard (single-select) MonthCalendar; scripts assuming SelectionItem.AddToSelection is always supported.
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
- SR.UIA_OperationCannotBePerformed
- Can only call SelectAll when SelectionMode is Multiple or…
- ElementNotEnabledException
- Microsoft.Windows.Controls.SR.UIA_OperationCannotBePerformed
- Operation cannot be performed.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/01ec297bc45d7876.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/WindowsCalendar.cs:3679
// Make sure that the control is enabled
if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
{
throw new ElementNotEnabledException();
}
ISelectionItemProvider selProvider = (ISelectionItemProvider) this;
// check if item already selected
if (selProvider.IsSelected)
{
return;
}
// if does not support multiple selection
// and other element(not us) is already selected return false
if (!WindowsCalendar.IsMultiSelect(_hwnd))
{
throw new InvalidOperationException(SR.DoesNotSupportMultipleSelection);
}
DateTime [] dateSelection =
WindowsCalendar.CreateDateTimeFromSystemTime (
WindowsCalendar.GetRawValue (_hwnd, WindowsCalendar.CalendarData.Selection));
DateTime itemDateTime = GetDateTime();
// Valid grid item but no date int the cell, before beginning or end of the week
if (itemDateTime == DateTime.MinValue)
{
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
// The day can only be added if it
TimeSpan ts = dateSelection[0] - itemDateTime;
if (ts.Days == 1)
{View on GitHub (pinned to 81131a70a4)