dotnet/wpf · error · System.ArgumentOutOfRangeException
SR.RangeValueMin
Error message
SR.RangeValueMin
What it means
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.
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
Example fix
// before rangeValue.SetValue(value); // may be below Minimum // after var info = rangeValue.Current; rangeValue.SetValue(Math.Max(info.Minimum, Math.Min(value, info.Maximum)));
Defensive patterns
Strategy: validation
Validate before calling
// C#: clamp to Minimum before calling SetValue var rv = (RangeValuePattern)scrollBar.GetCurrentPattern(RangeValuePattern.Pattern); var info = rv.Current; value = Math.Max(info.Minimum, value); rv.SetValue(value);
Type guard
bool InRange(RangeValuePattern.RangeValueInformation info, double v) =>
v >= info.Minimum && v <= info.Maximum; Try / catch
try
{
rv.SetValue(value);
}
catch (ArgumentOutOfRangeException)
{
rv.SetValue(Math.Max(rv.Current.Minimum, value));
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- SR.RangeValueMax
- ElementNotEnabledException
- Specified argument was out of the range of valid values…
- Specified argument was out of the range of valid values…
- Specified argument was out of the range of valid values…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/579760d67bccc1ce.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewScroll.cs:73
};
si.cbSize = Marshal.SizeOf (si.GetType ());
if (!Misc.GetScrollInfo(_hwnd, _sbFlag, ref si))
{
return;
}
int pos = (int)val;
// Throw if val is greater than the maximum or less than the minimum.
// See remarks for WindowsScrollBar.GetScrollValue(ScrollBarInfo.MaximumPosition)
// regarding this calculation of the allowed maximum.
if (pos > si.nMax - si.nPage + (si.nPage > 0 ? 1 : 0))
{
throw new ArgumentOutOfRangeException("value", val, SR.RangeValueMax);
}
else if (pos < si.nMin)
{
throw new ArgumentOutOfRangeException("value", val, SR.RangeValueMin);
}
// LVM_SCROLL does not work in mode Report, use SetScrollPos instead
bool isVerticalScroll = IsScrollBarVertical(_hwnd, _sbFlag);
if (isVerticalScroll && WindowsListView.InReportView (_hwnd))
{
Misc.SetScrollPos(_hwnd, _sbFlag, pos, true);
return;
}
// get the "full size" of the list-view
int size = WindowsListView.ApproximateViewRect (_hwnd);
// delta between current and user-requested position in pixels
// since the cPelsAll contains the dimension in pels for all items + the 2 pels of the border
// the operation below does a trunc on purpose
int dx = 0, dy = 0;
if (!isVerticalScroll)View on GitHub (pinned to 81131a70a4)