{"record":{"id":"579760d67bccc1ce","repo":"dotnet/wpf","slug":"sr-rangevaluemin","errorCode":null,"errorMessage":"SR.RangeValueMin","messagePattern":"SR\\.RangeValueMin","errorType":"validation","errorClass":"System.ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewScroll.cs","lineNumber":73,"sourceCode":"            };\n            si.cbSize = Marshal.SizeOf (si.GetType ());\n\n                if (!Misc.GetScrollInfo(_hwnd, _sbFlag, ref si))\n                {\n                    return;\n                }\n\n                int pos = (int)val;\n                // Throw if val is greater than the maximum or less than the minimum.\n                // See remarks for WindowsScrollBar.GetScrollValue(ScrollBarInfo.MaximumPosition)\n                // regarding this calculation of the allowed maximum.\n                if (pos > si.nMax - si.nPage + (si.nPage > 0 ? 1 : 0))\n                {\n                    throw new ArgumentOutOfRangeException(\"value\", val, SR.RangeValueMax);\n                }\n                else if (pos < si.nMin)\n                {\n                    throw new ArgumentOutOfRangeException(\"value\", val, SR.RangeValueMin);\n                }\n\n                // LVM_SCROLL does not work in mode Report, use SetScrollPos instead\n                bool isVerticalScroll = IsScrollBarVertical(_hwnd, _sbFlag);\n                if (isVerticalScroll && WindowsListView.InReportView (_hwnd))\n                {\n                    Misc.SetScrollPos(_hwnd, _sbFlag, pos, true);\n                    return;\n                }\n\n                // get the \"full size\" of the list-view\n                int size = WindowsListView.ApproximateViewRect (_hwnd);\n\n                // delta between current and user-requested position in pixels\n                // since the cPelsAll contains the dimension in pels for all items + the 2 pels of the border\n                // the operation below does a trunc on purpose\n                int dx = 0, dy = 0;\n                if (!isVerticalScroll)","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewScroll.cs#L55-L91","documentation":"IRangeValueProvider.SetValue on a list-view scroll bar throws ArgumentOutOfRangeException with SR.RangeValueMin when the requested position is less than the scroll bar's minimum (si.nMin from GetScrollInfo). The provider validates the value against the SCROLLINFO range before applying SetScrollPos or LVM_SCROLL.","triggerScenarios":"Calling RangeValuePattern.SetValue(val) with val < si.nMin on a WindowsListViewScroll provider — typically passing a negative position or a stale/other scroll bar's minimum into the call.","commonSituations":"Scripts assuming scroll positions start at 0 when nMin differs; passing values computed for a horizontal bar to a vertical bar; arithmetic errors producing negative positions.","solutions":["Clamp the requested value to at least si.nMin (RangeValue.Minimum) before calling SetValue","Query the current RangeValue.Minimum / GetScrollInfo right before the call instead of caching it","Catch ArgumentOutOfRangeException and clamp/retry within [Minimum, effective maximum]","Verify you are targeting the correct scroll bar (vertical vs horizontal via _sbFlag) and its actual range"],"exampleFix":"// before\nrangeValue.SetValue(value); // may be below Minimum\n\n// after\nvar info = rangeValue.Current;\nrangeValue.SetValue(Math.Max(info.Minimum, Math.Min(value, info.Maximum)));","handlingStrategy":"validation","validationCode":"// C#: clamp to Minimum before calling SetValue\nvar rv = (RangeValuePattern)scrollBar.GetCurrentPattern(RangeValuePattern.Pattern);\nvar info = rv.Current;\nvalue = Math.Max(info.Minimum, value);\nrv.SetValue(value);","typeGuard":"bool InRange(RangeValuePattern.RangeValueInformation info, double v) =>\n    v >= info.Minimum && v <= info.Maximum;","tryCatchPattern":"try\n{\n    rv.SetValue(value);\n}\ncatch (ArgumentOutOfRangeException)\n{\n    rv.SetValue(Math.Max(rv.Current.Minimum, value));\n}","preventionTips":["Always clamp values to [Minimum, effective maximum] before SetValue","Do not assume scroll minimum is 0; read Minimum from the pattern","Verify you are addressing the intended scroll bar (vertical vs horizontal)","Refresh the range after list content or layout changes"],"tags":["uiautomation","rangevaluepattern","argumentoutofrange","scrollbar"],"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-22T01:17:13.364Z"}