dotnet/wpf · error · ArgumentOutOfRangeException
SR.RangeValueMax
Error message
SR.RangeValueMax
What it means
WindowsSlider.SetSliderValue checks the requested value against the slider's Max property; val > Max throws ArgumentOutOfRangeException with SR.RangeValueMax. The slider (trackbar) control rejects RangeValue values above its maximum position.
Solutions
- Clamp the value to the slider's current [Min, Max] range read fresh via RangeValuePattern.Current before calling SetValue.
- Query the control's actual range (e.g. TBM_GETRANGE / RangeValue.Current.Maximum) instead of assuming 0-100.
- Catch ArgumentOutOfRangeException and retry with a clamped value.
Example fix
// before slider.SetValue(100); // after var rv = (RangeValuePattern)sliderElement.GetCurrentPattern(RangeValuePattern.Pattern); slider.SetValue(Math.Min(100, rv.Current.Maximum));
Defensive patterns
Strategy: validation
Validate before calling
var rv = (RangeValuePattern)element.GetCurrentPattern(RangeValuePattern.Pattern); val = Math.Clamp(val, rv.Current.Minimum, rv.Current.Maximum);
Try / catch
try { rv.SetValue(val); }
catch (ArgumentOutOfRangeException) { rv.SetValue(Math.Clamp(val, rv.Current.Minimum, rv.Current.Maximum)); } Prevention
- Query the slider's actual range instead of assuming 0-100
- Clamp all SetValue inputs with Math.Clamp
- Re-read range when slider configuration (min/max) can change at runtime
When it happens
Trigger: RangeValuePattern.SetValue on a slider-backed element with a value greater than the trackbar's current Max (TBM_GETRANGE), at WindowsSlider.cs:276.
Common situations: Hardcoding 100 when the trackbar range was configured smaller (e.g. 0-10); volume/brightness sliders whose range differs across Windows versions or drivers; using cached Maximum after the slider's range changed.
Related errors
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/652f268470965cc0.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSlider.cs:276
private int GetSliderValue ()
{
int value = Misc.ProxySendMessageInt(_hwnd, NativeMethods.TBM_GETPOS, IntPtr.Zero, IntPtr.Zero);
// adding support for if WindowsStyle has reversed bit set for the slider.
if ((this.WindowStyle & NativeMethods.TBS_REVERSED) != 0)
{
int maxValue = Misc.ProxySendMessageInt(_hwnd, NativeMethods.TBM_GETRANGEMAX, IntPtr.Zero, IntPtr.Zero);
value = maxValue - value;
}
return value;
}
private void SetSliderValue (int val)
{
// check for the range
if (val > Max)
{
throw new ArgumentOutOfRangeException("value", val, SR.RangeValueMax);
}
else if (val < Min)
{
throw new ArgumentOutOfRangeException("value", val, SR.RangeValueMin);
}
Misc.ProxySendMessage(_hwnd, NativeMethods.TBM_SETPOS, new IntPtr(1), new IntPtr(val));
}
private int LineSize
{
get
{
return Misc.ProxySendMessageInt(_hwnd, NativeMethods.TBM_GETLINESIZE, IntPtr.Zero, IntPtr.Zero);
}
}
private int MinView on GitHub (pinned to 81131a70a4)