dotnet/wpf · error · InvalidOperationException
SR.OperationCannotBePerformed
Error message
SR.OperationCannotBePerformed
What it means
The WindowsCalendar proxy cannot scroll vertically: if verticalPercent is anything other than ScrollPattern.NoScroll, SetScrollPercent throws InvalidOperationException(SR.OperationCannotBePerformed). The month calendar supports only horizontal scrolling.
Solutions
- Pass ScrollPattern.NoScroll for verticalPercent and only scroll horizontally.
- Query VerticalScrollPercent first; if it reports NoScroll, skip the vertical axis.
- Catch InvalidOperationException and handle vertical scrolling via another mechanism (keyboard/selection).
Example fix
// before scrollPattern.SetScrollPercent(50, 50); // after scrollPattern.SetScrollPercent(50, ScrollPattern.NoScroll);
Defensive patterns
Strategy: validation
Validate before calling
if ((int)verticalPercent != (int)ScrollPattern.NoScroll)
throw new InvalidOperationException("WindowsCalendar does not support vertical scrolling"); Type guard
bool SupportsVerticalScroll(IScrollProvider sp) => sp.VerticalScrollPercent != ScrollPattern.NoScroll;
Try / catch
try { scrollPattern.SetScrollPercent(h, v); }
catch (InvalidOperationException) { /* vertical not supported; scroll horizontally only */ } Prevention
- Pass ScrollPattern.NoScroll for unsupported axes
- Read VerticalScrollPercent first to detect NoScroll capability
- Use keyboard/selection navigation for vertical month movement
When it happens
Trigger: Calling IScrollProvider.SetScrollPercent with a verticalPercent other than ScrollPattern.NoScroll (e.g. 50) on a month-calendar element.
Common situations: Generic scroll automation scripts that set both axes on every control; assuming the calendar behaves like a scrollable list.
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
- ElementNotEnabledException
- SR.DoesNotSupportMultipleSelection
- SR.DoesNotSupportMultipleSelection
- SR.Format(SR.RichEditTextPatternHasNoChildren…
- SR.OperationCannotBePerformed
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/35094066db1ec5c9.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/WindowsCalendar.cs:359
return base.ElementProviderFromPoint (x, y);
}
#endregion
#region Scroll Pattern
// Request to scroll Horizontally and vertically by the specified amount
void IScrollProvider.SetScrollPercent (double horizontalPercent, double verticalPercent)
{
// Make sure that the control is enabled
if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
{
throw new ElementNotEnabledException();
}
if ((int)verticalPercent != (int)ScrollPattern.NoScroll)
{
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
else if ((int)horizontalPercent == (int)ScrollPattern.NoScroll)
{
return;
}
else if (horizontalPercent < 0 || horizontalPercent > 100)
{
throw new ArgumentOutOfRangeException("horizontalPercent", SR.ScrollBarOutOfRange);
}
int cDisplayedMonths = GetMonthCount();
DateTime [] dateRange =
CreateDateTimeFromSystemTime (GetRawValue (_hwnd, CalendarData.Range));
int cMonths = (dateRange [1].Year - dateRange [0].Year) * 12
+ (dateRange [1].Month - dateRange [0].Month) + 1;
if (cMonths <= cDisplayedMonths)
{View on GitHub (pinned to 81131a70a4)