{"record":{"id":"c38dfd9b59864331","repo":"dotnet/wpf","slug":"sr-rangevaluemin-windowsscrollbar","errorCode":null,"errorMessage":"SR.RangeValueMin","messagePattern":"SR\\.RangeValueMin","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsScrollBar.cs","lineNumber":683,"sourceCode":"            string classname = Misc.GetClassName(_hwnd);\n            if (classname.ToLower(System.Globalization.CultureInfo.InvariantCulture).Contains(\"richedit\"))\n            {\n                max = si.nMax - si.nPage;\n            }\n            else\n            {\n                max = (si.nMax - si.nPage) + (si.nPage > 0 ? 1 : 0);\n            }\n\n            // Explicit comparisions are made to the MaxPercentage and MinPercentage,\n            // so that we dont miss out the fractions\n            if (val > max )\n            {\n                throw new ArgumentOutOfRangeException(\"value\", val, SR.RangeValueMax);\n            }\n            else if (val < si.nMin)\n            {\n                throw new ArgumentOutOfRangeException(\"value\", val, SR.RangeValueMin);\n            }\n\n            if (_sbFlag == NativeMethods.SB_CTL)\n            {\n                Misc.SetScrollPos(_hwnd, _sbFlag, val, true);\n            }\n            else\n            {\n                // Determine the msg from the style.\n                int msg =\n                    IsScrollBarVertical(_hwnd, _sbFlag) ? NativeMethods.WM_VSCROLL : NativeMethods.WM_HSCROLL;\n\n                // An application is generally programmed to process either the\n                // SB_THUMBTRACK or SB_THUMBPOSITION request code.\n                int wParam = NativeMethods.Util.MAKELONG ((short) NativeMethods.SB_THUMBPOSITION, (short) val);\n                Misc.ProxySendMessage(_hwnd, msg, (IntPtr)wParam, IntPtr.Zero);\n                wParam = NativeMethods.Util.MAKELONG ((short) NativeMethods.SB_THUMBTRACK, (short) val);\n                Misc.ProxySendMessage(_hwnd, msg, (IntPtr)wParam, IntPtr.Zero);","sourceCodeStart":665,"sourceCodeEnd":701,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsScrollBar.cs#L665-L701","documentation":"WindowsScrollBar.SetScrollValue validates the lower bound: if val < si.nMin (the scrollbar's minimum from GetScrollInfo) it throws ArgumentOutOfRangeException with SR.RangeValueMin. RangeValue values below the control's minimum are rejected.","triggerScenarios":"RangeValuePattern.SetValue with a value smaller than the scrollbar's nMin, at WindowsScrollBar.cs:683 — e.g. passing 0 or a negative value on a scrollbar whose min is not 0.","commonSituations":"Assuming scrollbar range starts at 0; using cached Minimum after the control changed range; off-by-one math when converting positions to percentages.","solutions":["Clamp the value to at least RangeValue.Current.Minimum before calling SetValue.","Refresh the pattern properties immediately before the call rather than using stale cached values.","Catch ArgumentOutOfRangeException and retry with the clamped value."],"exampleFix":"// before\nrangeValue.SetValue(0);\n// after\nvar rv = (RangeValuePattern)el.GetCurrentPattern(RangeValuePattern.Pattern);\nrangeValue.SetValue(Math.Max(0, rv.Current.Minimum));","handlingStrategy":"validation","validationCode":"var rv = (RangeValuePattern)element.GetCurrentPattern(RangeValuePattern.Pattern);\nval = Math.Max(val, rv.Current.Minimum);","typeGuard":null,"tryCatchPattern":"try { rv.SetValue(val); }\ncatch (ArgumentOutOfRangeException) { rv.SetValue(rv.Current.Minimum); }","preventionTips":["Do not assume scrollbar minimum is 0","Clamp to [Minimum, Maximum] from the pattern's live properties","Refresh cached range values when the control's content changes"],"tags":["uiautomation","argument-out-of-range","range-value-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"}