dotnet/wpf · error · ArgumentException

SR.InvalidParameter

Error message

SR.InvalidParameter

What it means

IRangeValueProvider.SetValue on the Windows Up/Down proxy throws ArgumentException(SR.InvalidParameter) when the requested value is double.NaN. NaN is not a representable position for the native UDM_SETPOS control, so the provider rejects it as an invalid parameter.

Solutions

  1. Validate the value is a real number (double.IsNaN / IsFinite) before calling SetValue
  2. Fix the upstream calculation producing NaN
  3. Clamp/default NaN inputs to Min or a configured default before invoking the pattern
  4. Catch ArgumentException around SetValue and log the offending value

Example fix

// before
rangeValuePattern.SetValue(value); // value may be NaN
// after
if (double.IsNaN(value)) value = rangeValuePattern.Current.Minimum;
rangeValuePattern.SetValue(value);
Defensive patterns

Strategy: validation

Validate before calling

if (double.IsNaN(value) || double.IsInfinity(value)) value = rangeValuePattern.Current.Minimum;

Type guard

bool IsValidSpinnerValue(double v) => !double.IsNaN(v) && !double.IsInfinity(v);

Try / catch

try { rangeValuePattern.SetValue(value); }
catch (ArgumentException) { log($"Invalid spinner value: {value}"); }

Prevention

When it happens

Trigger: Calling RangeValuePattern.SetValue(double.NaN) on a Spinner element. Any automation caller passing an unset/uninitialized double (default comparisons or computed NaN) reaches this check after the enabled check passes.

Common situations: Test data binding bugs where a NaN leaks from a computation; callers using double fields never initialized; frameworks that pass through RangeValue.CurrentValue-like NaN sentinels.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

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

            return this;
        }

        #endregion

        #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);
        }

View on GitHub (pinned to 81131a70a4)