dotnet/wpf · error · ArgumentOutOfRangeException

SR.RangeValueMin

Error message

SR.RangeValueMin

What it means

WindowsSlider.SetSliderValue validates the requested slider position against the control's Min/Max range before sending TBM_SETPOS to the underlying Win32 trackbar. An ArgumentOutOfRangeException with SR.RangeValueMin is thrown when the caller requests a value below the slider's minimum. This enforces the IRangeValueProvider contract that SetValue only accepts in-range values.

Solutions

  1. Read the slider's IRangeValueProvider.Minimum and clamp the target value into [Minimum, Maximum] before calling SetValue.
  2. Cast the double RangeValue value to int within range, since WindowsSlider.SetValue takes an int trackbar position.
  3. Re-query the element after UI changes; stale cached Min/Max leads to out-of-range requests.

Example fix

// before
slider.SetValue(-5);
// after
double min = rangeValuePattern.Current.Minimum;
double v = Math.Max(min, Math.Min(rangeValuePattern.Current.Maximum, desired));
slider.SetValue((int)v);
Defensive patterns

Strategy: validation

Validate before calling

var rv = slider.GetCurrentPattern(RangeValuePattern.Pattern) as RangeValuePattern;
double min = rv.Current.Minimum, max = rv.Current.Maximum;
if (desired < min || desired > max) desired = Math.Max(min, Math.Min(max, desired));

Type guard

static bool IsInRange(RangeValuePattern rv, double v) => v >= rv.Current.Minimum && v <= rv.Current.Maximum;

Try / catch

try { slider.SetValue((int)v); }
catch (ArgumentOutOfRangeException ex) { /* clamp and retry */ }

Prevention

When it happens

Trigger: Calling IRangeValueProvider.SetValue on a slider (UIA ValuePattern/RangeValue pattern backed by WindowsSlider) with a value less than the control's current Minimum.

Common situations: Automation scripts computing target positions from hard-coded constants instead of reading RangeValue.Minimum; UI layout changes that raised a slider's minimum; unit tests feeding 0 or -1 to sliders whose Min is higher.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/ee0a40f2e0094ada. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSlider.cs:280

            // 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 Min
        {
            get
            {
                return Misc.ProxySendMessageInt(_hwnd, NativeMethods.TBM_GETRANGEMIN, IntPtr.Zero, IntPtr.Zero);

View on GitHub (pinned to 81131a70a4)