{"record":{"id":"3749e2503bc14b23","repo":"dotnet/wpf","slug":"sr-scrollbaroutofrange-windowsscroll","errorCode":null,"errorMessage":"SR.ScrollBarOutOfRange","messagePattern":"SR\\.ScrollBarOutOfRange","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsScroll.cs","lineNumber":283,"sourceCode":"\n        // Request to scroll a control horizontally or vertically by a specified amount.\n        private static bool SetScrollPercent(IntPtr hwnd, double fScrollPos, int sbFlag, out bool forceResults)\n        {\n            forceResults = false;\n            // Check param\n            if ((int)fScrollPos == (int)ScrollPattern.NoScroll)\n            {\n                return true;\n            }\n\n            if (!Scrollable(hwnd, sbFlag))\n            {\n                return false;\n            }\n\n            if (fScrollPos < 0 || fScrollPos > 100)\n            {\n                throw new ArgumentOutOfRangeException(sbFlag == NativeMethods.SB_HORZ ? \"horizontalPercent\" : \"verticalPercent\", SR.ScrollBarOutOfRange);\n            }\n\n            // Get Max & min                    \n            NativeMethods.ScrollInfo si = new NativeMethods.ScrollInfo\n            {\n                fMask = NativeMethods.SIF_ALL\n            };\n            si.cbSize = Marshal.SizeOf(si.GetType ());\n\n            // if no scroll bar return false\n            // on Win 6.0 success is false\n            // on other system check through the scroll info is a scroll bar is there\n            if (!Misc.GetScrollInfo(hwnd, sbFlag, ref si) ||\n                !((si.nMax != si.nMin && si.nPage != si.nMax - si.nMin + 1)))\n            {\n                return false;\n            }\n","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsScroll.cs#L265-L301","documentation":"The per-axis helper inside WindowsScroll.SetScrollPercent validates the requested percent before issuing the Win32 scroll: values below 0 or above 100 throw ArgumentOutOfRangeException with SR.ScrollBarOutOfRange. The parameter name reported depends on which bar (horizontalPercent or verticalPercent) is out of range.","triggerScenarios":"ScrollPattern.SetScrollPercent called with a value < 0 or > 100 (and not the NoScroll sentinel) for the horizontal or vertical axis, caught at WindowsScroll.cs:283.","commonSituations":"Computing a percent from element bounds and producing e.g. 150 or -5; forgetting that -1 is the special NoScroll sentinel and passing -2; unit confusion (0.0-1.0 fraction passed instead of 0-100 percent).","solutions":["Clamp the computed percentage to the 0-100 range before calling SetScrollPercent.","Use ScrollPattern.NoScroll (-1), not 0 or other negatives, to mean 'do not scroll this axis'.","Catch ArgumentOutOfRangeException and clamp/retry with a valid value."],"exampleFix":"// before\nscrollPattern.SetScrollPercent(fraction, ScrollPattern.NoScroll); // fraction = 0.75\n// after\nscrollPattern.SetScrollPercent(Math.Max(0, Math.Min(100, fraction * 100)), ScrollPattern.NoScroll);","handlingStrategy":"validation","validationCode":"double pct = Math.Max(0, Math.Min(100, computedPercent));\nsp.SetScrollPercent(pct, ScrollPattern.NoScroll);","typeGuard":null,"tryCatchPattern":"try { sp.SetScrollPercent(pct, ScrollPattern.NoScroll); }\ncatch (ArgumentOutOfRangeException) { sp.SetScrollPercent(Math.Clamp(pct, 0, 100), ScrollPattern.NoScroll); }","preventionTips":["Remember valid range is 0-100 inclusive; use -1 (NoScroll) to skip an axis","Convert fractions (0-1) to percentages (0-100) explicitly","Clamp computed percentages before every call"],"tags":["uiautomation","argument-out-of-range","scroll-pattern","wpf"],"backgroundTag":"argument-out-of-range","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"}