{"record":{"id":"1c3c8c866779670f","repo":"dotnet/wpf","slug":"sr-scrollbaroutofrange-windowstab","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/WindowsTab.cs","lineNumber":492,"sourceCode":"                throw new ElementNotEnabledException();\n            }\n\n            if (!IsScrollable())\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);\n            }\n\n            if ((int)verticalPercent != (int)ScrollPattern.NoScroll)\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);\n            }\n            else if ((int)horizontalPercent == (int)ScrollPattern.NoScroll)\n            {\n                return;\n            }\n            else if (horizontalPercent < 0 || horizontalPercent > 100)\n            {\n                throw new ArgumentOutOfRangeException(nameof(horizontalPercent), SR.ScrollBarOutOfRange);\n            }\n\n            // Get up/down control's hwnd\n            IntPtr updownHwnd = this.GetUpDownHwnd ();\n\n            if (updownHwnd == IntPtr.Zero)\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);\n            }\n\n            // Get available range\n            int range = Misc.ProxySendMessageInt(updownHwnd, NativeMethods.UDM_GETRANGE, IntPtr.Zero, IntPtr.Zero);\n            int minPos = NativeMethods.Util.HIWORD(range);\n            int maxPos = NativeMethods.Util.LOWORD(range);\n\n            // Calculate new position\n            int newPos = (int) Math.Round ((maxPos - minPos) * horizontalPercent / 100) + minPos;\n","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsTab.cs#L474-L510","documentation":"WindowsTab.SetScrollPercent validates the horizontal scroll percent and throws ArgumentOutOfRangeException(SR.ScrollBarOutOfRange) when the value is outside 0..100 (and not ScrollPattern.NoScroll). Scroll percentages must be expressed as a percentage of the total scrollable range, so negative values or values above 100 are meaningless.","triggerScenarios":"Calling ScrollPattern.SetScrollPercent(h, v) on a WindowsTab proxy where horizontalPercent < 0 or horizontalPercent > 100, and it is not ScrollPattern.NoScroll.","commonSituations":"Computing scroll positions with float rounding that yields 100.4; passing pixel positions instead of percentages; copy-pasted code using -1 as a sentinel other than ScrollPattern.NoScroll.","solutions":["Clamp the percentage: Math.Max(0.0, Math.Min(100.0, percent)) before calling.","Use ScrollPattern.NoScroll (-1) explicitly for 'do not scroll' instead of 0 or negative sentinels.","Verify the value fits 0..100 after any normalization/conversion from pixel offsets."],"exampleFix":"// before\ntab.SetScrollPercent(150.0, -1);\n// after\ndouble pct = Math.Clamp(150.0, 0.0, 100.0);\ntab.SetScrollPercent(pct, ScrollPattern.NoScroll);","handlingStrategy":"validation","validationCode":"if (percent != ScrollPattern.NoScroll && (percent < 0 || percent > 100))\n    throw new ArgumentException(\"percent must be 0..100 or ScrollPattern.NoScroll\");","typeGuard":"static bool IsValidScrollPercent(double p) => p == ScrollPattern.NoScroll || (p >= 0 && p <= 100);","tryCatchPattern":"try { sp.SetScrollPercent(h, v); }\ncatch (ArgumentOutOfRangeException ex) { /* ex.ParamName == \"horizontalPercent\" */ }","preventionTips":["Clamp computed percentages with Math.Clamp","Use ScrollPattern.NoScroll constant, never raw -1 sentinels","Convert pixels to percentages before calling"],"tags":["uiautomation","argument-out-of-range","scrollpattern","wpf"],"backgroundTag":"value-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}