dotnet/wpf · error · InvalidOperationException
SR.UIA_OperationCannotBePerformed
Error message
SR.UIA_OperationCannotBePerformed
What it means
ScrollViewerAutomationPeer.Scroll throws InvalidOperationException(SR.UIA_OperationCannotBePerformed) when a scroll amount is requested on an axis that is not scrollable. If horizontal scrolling is requested while HorizontallyScrollable is false, or vertical while VerticallyScrollable is false, the operation cannot be performed.
Solutions
- Check the Scroll pattern's HorizontallyScrollable/VerticallyScrollable properties before calling Scroll
- Pass ScrollAmount.NoAmount for the non-scrollable axis
- Ensure content is large enough / ScrollViewer allows scrolling on that axis
- Catch InvalidOperationException and treat as no-op
Example fix
// before
scrollPattern.Scroll(ScrollAmount.SmallIncrement, ScrollAmount.NoAmount);
// after
if (scrollPattern HorizontallyScrollable)
scrollPattern.Scroll(ScrollAmount.SmallIncrement, ScrollAmount.NoAmount); Defensive patterns
Strategy: validation
Validate before calling
var sp = (IScrollProvider)peer.GetPattern(PatternInterface.Scroll);
bool ok = (h == ScrollAmount.NoAmount || sp.HorizontallyScrollable)
&& (v == ScrollAmount.NoAmount || sp.VerticallyScrollable); Type guard
static bool CanScrollAxis(IScrollProvider sp, ScrollAmount h, ScrollAmount v) =>
(h == ScrollAmount.NoAmount || sp.HorizontallyScrollable) &&
(v == ScrollAmount.NoAmount || sp.VerticallyScrollable); Try / catch
try { sp.Scroll(h, v); }
catch (InvalidOperationException) { /* axis not scrollable */ } Prevention
- Query HorizontallyScrollable/VerticallyScrollable before Scroll
- Use NoAmount for non-scrollable axes
- Ensure ScrollViewer extent exceeds viewport on the axis you scroll
- Account for ScrollViewer scroll bar visibility settings
When it happens
Trigger: Calling Scroll with a non-NoAmount horizontal amount when ScrollViewer.HorizontalScrollBarVisibility/extent makes it non-scrollable (ScrollUnit-based HorizontallyScrollable property false), or same for vertical.
Common situations: Requesting horizontal scroll on a viewer whose content fits horizontally (scrollbar hidden); scripts assuming both axes are scrollable.
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.Automation_RecursivePublicCall
- SR.Format(SR.ScrollViewer_OutOfRange, "horizontalPercent"…
- SR.TextProvider_InvalidChildElement
- SR.TextProvider_TextSelectionNotSupported
- SR.UIA_OperationCannotBePerformed
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e50b281d74b82fce.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ScrollViewerAutomationPeer.cs:85
/// <summary>
/// Request to scroll horizontally and vertically by the specified amount.
/// The ability to call this method and simultaneously scroll horizontally
/// and vertically provides simple panning support.
/// </summary>
/// <see cref="IScrollProvider.Scroll"/>
void IScrollProvider.Scroll(ScrollAmount horizontalAmount, ScrollAmount verticalAmount)
{
if(!IsEnabled())
throw new ElementNotEnabledException();
bool scrollHorizontally = (horizontalAmount != ScrollAmount.NoAmount);
bool scrollVertically = (verticalAmount != ScrollAmount.NoAmount);
ScrollViewer owner = (ScrollViewer)Owner;
if (scrollHorizontally && !HorizontallyScrollable || scrollVertically && !VerticallyScrollable)
{
throw new InvalidOperationException(SR.UIA_OperationCannotBePerformed);
}
switch (horizontalAmount)
{
case ScrollAmount.LargeDecrement:
owner.PageLeft();
break;
case ScrollAmount.SmallDecrement:
owner.LineLeft();
break;
case ScrollAmount.SmallIncrement:
owner.LineRight();
break;
case ScrollAmount.LargeIncrement:
owner.PageRight();
break;
case ScrollAmount.NoAmount:
break;View on GitHub (pinned to 81131a70a4)