dotnet/wpf · error · ArgumentOutOfRangeException

SR.RangeValueMax

Error message

SR.RangeValueMax

What it means

SetValue on the Windows Up/Down RangeValue provider throws ArgumentOutOfRangeException with SR.RangeValueMax when the requested value exceeds the control's Maximum. The native updown control has finite bounds and positions above Max are rejected before sending UDM_SETPOS.

Solutions

  1. Clamp the value to the pattern's Maximum before calling SetValue
  2. Re-read RangeValuePattern.Maximum instead of caching it
  3. Fix the application's UDM_SETRANGE32 configuration if the range is wrong
  4. Catch ArgumentOutOfRangeException and report value/min/max in the test failure

Example fix

// before
rangeValuePattern.SetValue(value);
// after
var rv = rangeValuePattern.Current;
rangeValuePattern.SetValue(Math.Min(Math.Max(value, rv.Minimum), rv.Maximum));
Defensive patterns

Strategy: validation

Validate before calling

var rv = rangeValuePattern.Current;
value = Math.Clamp(value, rv.Minimum, rv.Maximum);

Type guard

bool InRange(double v, double min, double max) => v >= min && v <= max;

Try / catch

try { rangeValuePattern.SetValue(value); }
catch (ArgumentOutOfRangeException ex) { log($"{value} outside spinner range"); }

Prevention

When it happens

Trigger: Calling RangeValuePattern.SetValue(val) where val > Max (the provider's Maximum property, derived from the control's UDM_GETRANGE). E.g. setting 200 on a spinner whose range tops out at 100.

Common situations: Hard-coded test values exceeding the control's configured range; app changed the spinner's Max without updating tests; callers clamping against a stale cached Maximum.

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/cecc2723388998c1. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsUpDown.cs:215

        #region RangeValue Pattern

        // Change the position of the Up/Down
        void IRangeValueProvider.SetValue (double val)
        {
            // Make sure that the control is enabled
            if (!SafeNativeMethods.IsWindowEnabled (_hwnd))
            {
                throw new ElementNotEnabledException();
            }

            if (double.IsNaN(val))
            {
                throw new ArgumentException(SR.InvalidParameter);
            }

            if (val > Max)
            {
                throw new ArgumentOutOfRangeException("value", val, SR.RangeValueMax);
            }
            else if (val < Min)
            {
                throw new ArgumentOutOfRangeException("value", val, SR.RangeValueMin);
            }

            short newPos = Convert.ToInt16(val);
            Misc.ProxySendMessage(_hwnd, NativeMethods.UDM_SETPOS, IntPtr.Zero, NativeMethods.Util.MAKELPARAM(newPos, 0));

            // Scroll the buddy
            Misc.ProxySendMessage(HwndBuddy(_hwnd), NativeMethods.WM_HSCROLL, NativeMethods.Util.MAKELPARAM(NativeMethods.SB_THUMBPOSITION, newPos), IntPtr.Zero);
        }

        // Request to get the value that this UI element is representing in a native format
        double IRangeValueProvider.Value
        {
            get
            {

View on GitHub (pinned to 81131a70a4)