{"record":{"id":"9bd272a9368d0f8b","repo":"dotnet/wpf","slug":"sr-operationcannotbeperformed-windowsscroll","errorCode":null,"errorMessage":"SR.OperationCannotBePerformed","messagePattern":"SR\\.OperationCannotBePerformed","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsScroll.cs","lineNumber":31,"sourceCode":"namespace MS.Internal.AutomationProxies\n{\n    // Static class used to support the Scroll pattern for controls that have scroll bars. \n    internal static class WindowScroll\n    {\n        #region Internal Methods\n\n        // ------------------------------------------------------\n        //\n        // Internal Methods\n        //\n        // ------------------------------------------------------\n\n        // Request to scroll Horizontally and vertically by the specified amount\n        internal static void SetScrollPercent (IntPtr hwnd, double horizontalPercent, double verticalPercent, bool forceResults)\n        {\n            if (!IsScrollable(hwnd))\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);\n            }\n\n            bool resultsNoCheck;\n            bool isHorizontal = SetScrollPercent (hwnd, horizontalPercent, NativeMethods.SB_HORZ, out resultsNoCheck);\n\n            // This is needed for Controls that do not return the proper return codes to WinAPI Calls\n            if (!isHorizontal && (forceResults && resultsNoCheck))\n            {\n                isHorizontal = true;\n            }\n\n            bool isVertical = SetScrollPercent (hwnd, verticalPercent, NativeMethods.SB_VERT, out resultsNoCheck);\n\n            // This is needed for Controls that do not return the proper return codes to WinAPI Calls\n            if (!isVertical && (forceResults && resultsNoCheck))\n            {\n                isVertical = true;\n            }","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsScroll.cs#L13-L49","documentation":"WindowsScroll.SetScrollPercent first verifies the window actually has a scrollable bar via IsScrollable(hwnd); if not, it throws InvalidOperationException with SR.OperationCannotBePerformed. UIAutomation's Scroll pattern was invoked on a control that cannot be scrolled in the requested direction.","triggerScenarios":"Calling the Scroll pattern's SetScrollPercent (ScrollPattern.SetScrollPercent) on a window whose scroll bars are disabled or non-scrollable (IsScrollable returns false), detected at WindowsScroll.cs:31.","commonSituations":"Automating a list/view whose content currently fits without scrolling; scroll bars hidden because 'auto-hide scroll bars' is on; targeting a child control that has no scroll style bits (WS_HSCROLL/WS_VSCROLL).","solutions":["Check ScrollPattern.ScrollInfo / IsScrollable before calling SetScrollPercent and skip when not scrollable.","Ensure the target control actually shows scroll bars (resize the window or populate more content) before automating.","Catch InvalidOperationException and treat the element as non-scrollable instead of failing the automation run."],"exampleFix":"// before\nscrollPattern.SetScrollPercent(50, ScrollPattern.NoScroll);\n// after\nif (scrollPattern.Current.VerticallyScrollable)\n    scrollPattern.SetScrollPercent(ScrollPattern.NoScroll, 50);","handlingStrategy":"validation","validationCode":"var sp = (ScrollPattern)element.GetCurrentPattern(ScrollPattern.Pattern);\nbool ok = sp.Current.HorizontallyScrollable || sp.Current.VerticallyScrollable;","typeGuard":null,"tryCatchPattern":"try { sp.SetScrollPercent(h, v); }\ncatch (InvalidOperationException) { /* element is not scrollable; skip */ }","preventionTips":["Check HorizontallyScrollable/VerticallyScrollable before SetScrollPercent","Re-read scrollability after layout or content changes","Handle auto-hidden scroll bars by forcing content overflow in test fixtures"],"tags":["uiautomation","invalid-operation","scroll-pattern","wpf"],"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"}