dotnet/wpf · error · ArgumentOutOfRangeException

Specified argument was out of the range of valid values…

Error message

Specified argument was out of the range of valid values. (Parameter 'value') Value is less than Minimum.

What it means

WindowsIPAddress's IRangeValueProvider.SetValue throws ArgumentOutOfRangeException when the requested value is below the RangeValue Minimum of 0. Octet values are unsigned bytes; negative values are rejected after the control-enabled check.

Solutions

  1. Clamp the value to 0-255 before calling SetValue
  2. Check RangeValuePattern.Minimum (0) before setting
  3. Catch ArgumentOutOfRangeException and validate input at the boundary
  4. Use unsigned/validated sources for octet values

Example fix

// before
rangeValue.SetValue(-1);
// after
int octet = Math.Clamp(-1, 0, 255);
rangeValue.SetValue(octet);
Defensive patterns

Strategy: validation

Validate before calling

int octet = (int)val;
if (octet < 0) octet = 0; // or reject
if (octet > 255) octet = 255;

Try / catch

try { rangeValue.SetValue(val); }
catch (ArgumentOutOfRangeException) { /* clamp to 0..255 or reject negative input */ }

Prevention

When it happens

Trigger: Calling IRangeValueProvider.SetValue with a negative double such as -1, or with a value whose cast to int is negative, on an IP octet field.

Common situations: Unclamped arithmetic (e.g. subtracting octets); signed data types from callers; test generators producing negative boundary values.

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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsIPAddress.cs:376

        // Sets the one of the field of the IP Address.
        void IRangeValueProvider.SetValue(double val)
        {
            // Make sure that the control is enabled
            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
            {
                throw new ElementNotEnabledException();
            }

            int i = (int)val;

            // Check range
            if (i > 255)
            {
                throw new ArgumentOutOfRangeException("value", val, SR.RangeValueMax);
            }
            if (i < 0)
            {
                throw new ArgumentOutOfRangeException("value", val, SR.RangeValueMin);
            }

            // Set text
            Misc.ProxySendMessage(_hwnd, NativeMethods.WM_SETTEXT, IntPtr.Zero, new StringBuilder(i.ToString(CultureInfo.CurrentCulture)));
        }

        // Request to get the value that this UI element is representing in a native format
        double IRangeValueProvider.Value
        {
            get
            {
                string s = WindowsEditBox.Text(_hwnd);
                if (string.IsNullOrEmpty(s))
                {
                    return double.NaN;
                }
                return double.Parse(s, CultureInfo.CurrentCulture);
            }

View on GitHub (pinned to 81131a70a4)