{"record":{"id":"5de022e0314554fe","repo":"dotnet/wpf","slug":"throw-new-invalidoperationexception-sr-windowspager","errorCode":null,"errorMessage":"throw new InvalidOperationException(SR.OperationCannotBePerformed);","messagePattern":"throw new InvalidOperationException\\(SR\\.OperationCannotBePerformed\\);","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/windowspager.cs","lineNumber":253,"sourceCode":"            return null;\n        }\n\n        #endregion IRawElementProviderHwndOverride Interface \n    \n        #region Scroll Pattern\n\n        // Request to scroll Horizontally and vertically by the specified amount\n        void IScrollProvider.SetScrollPercent (double horizontalPercent, double verticalPercent)\n        {\n            // Make sure that the control is enabled\n            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n            {\n                throw new ElementNotEnabledException();\n            }\n\n            if (!IsScrollable())\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);\n            }\n\n            bool fHorizontal = IsHorizontal(_hwnd);\n\n            // Can scroll either horizontally or vertically, but not both. Sanity check\n            if ((fHorizontal && (int)verticalPercent != (int)ScrollPattern.NoScroll) || \n                (!fHorizontal && (int)horizontalPercent != (int)ScrollPattern.NoScroll))\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);\n            }\n\n            if (!ScrollByPercent(fHorizontal ? horizontalPercent : verticalPercent))\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);\n            }\n        }\n\n        // Request to scroll horizontally and vertically by the specified scrolling amount","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/windowspager.cs#L235-L271","documentation":"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.","triggerScenarios":"Calling SetScrollPercent on a pager element whose IsScrollable() check fails — i.e. the control reports no scrollable range (after passing the enabled check).","commonSituations":"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.","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"],"exampleFix":"// before\nscrollPattern.SetScrollPercent(50);\n// after\nif (scrollPattern.Current.IsScrollable)\n{\n    scrollPattern.SetScrollPercent(50);\n}","handlingStrategy":"validation","validationCode":"if (!scrollPattern.Current.IsScrollable) return; // skip non-scrollable pager\nscrollPattern.SetScrollPercent(pct, ScrollPattern.NoScroll);","typeGuard":"static bool CanScroll(AutomationElement el) =>\n    el.TryGetCurrentPattern(ScrollPattern.Pattern, out var p) && ((ScrollPattern)p).Current.IsScrollable;","tryCatchPattern":"try { scrollPattern.SetScrollPercent(pct); }\ncatch (InvalidOperationException) { /* element not scrollable */ }","preventionTips":["Check ScrollPattern.IsScrollable before every scroll call","Treat unsupported proxies (pager) as one-dimensional scrollers","Read HorizontalScrollPercent/VerticalScrollPercent to detect NoScroll orientation"],"tags":["uiautomation","scroll-pattern","wpf","win32"],"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"}