dotnet/wpf · error · InvalidOperationException
throw new…
Error message
throw new InvalidOperationException(SR.OperationCannotBePerformed);
What it means
The WindowsPager proxy (an unsupported proxy for the Win32 pager control) implements IScrollProvider.SetScrollPercent. It throws InvalidOperationException(OperationCannotBePerformed) when IsScrollable() reports the pager has no scrollable content, so a scroll-percent operation cannot be performed.
Solutions
- Check the element's ScrollPattern.IsScrollable property (or IScrollProvider.GetIsScrollable) before calling SetScrollPercent
- Only call SetScrollPercent when the pager actually displays fewer than all of its content
- Catch InvalidOperationException and treat the element as non-scrollable / already at correct position
Example fix
// before
scrollPattern.SetScrollPercent(50);
// after
if (scrollPattern.Current.IsScrollable)
{
scrollPattern.SetScrollPercent(50);
} Defensive patterns
Strategy: validation
Validate before calling
if (!scrollPattern.Current.IsScrollable) return; // skip non-scrollable pager scrollPattern.SetScrollPercent(pct, ScrollPattern.NoScroll);
Type guard
static bool CanScroll(AutomationElement el) =>
el.TryGetCurrentPattern(ScrollPattern.Pattern, out var p) && ((ScrollPattern)p).Current.IsScrollable; Try / catch
try { scrollPattern.SetScrollPercent(pct); }
catch (InvalidOperationException) { /* element not scrollable */ } Prevention
- Check ScrollPattern.IsScrollable before every scroll call
- Treat unsupported proxies (pager) as one-dimensional scrollers
- Read HorizontalScrollPercent/VerticalScrollPercent to detect NoScroll orientation
When it happens
Trigger: Calling SetScrollPercent on a pager element whose IsScrollable() check fails — i.e. the control reports no scrollable range (after passing the enabled check).
Common situations: Automating a pager control that is fully showing its child (no scrolling needed), or querying scroll state before the pager has sized its content; also hit when binding ScrollPattern.SetScrollPercent to a non-scrollable pager.
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.OperationCannotBePerformed
- SR.ScrollBarOutOfRange
- throw new ArgumentOutOfRangeException(IsHorizontal(_hwnd) ?…
- ArgumentNullException
- E_ACCESSDENIED
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/5de022e0314554fe.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/windowspager.cs:253
return null;
}
#endregion IRawElementProviderHwndOverride Interface
#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 (!IsScrollable())
{
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
bool fHorizontal = IsHorizontal(_hwnd);
// Can scroll either horizontally or vertically, but not both. Sanity check
if ((fHorizontal && (int)verticalPercent != (int)ScrollPattern.NoScroll) ||
(!fHorizontal && (int)horizontalPercent != (int)ScrollPattern.NoScroll))
{
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
if (!ScrollByPercent(fHorizontal ? horizontalPercent : verticalPercent))
{
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
}
// Request to scroll horizontally and vertically by the specified scrolling amountView on GitHub (pinned to 81131a70a4)