{"record":{"id":"cbaf2ab8cdf37348","repo":"dotnet/wpf","slug":"specified-argument-was-out-of-the-range-of-valid-values-cbaf2a","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'value') Value is less than Minimum.","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'value'\\) Value is less than Minimum\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsIPAddress.cs","lineNumber":376,"sourceCode":"        // Sets the one of the field of the IP Address.\n        void IRangeValueProvider.SetValue(double val)\n        {\n            // Make sure that the control is enabled\n            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n            {\n                throw new ElementNotEnabledException();\n            }\n\n            int i = (int)val;\n\n            // Check range\n            if (i > 255)\n            {\n                throw new ArgumentOutOfRangeException(\"value\", val, SR.RangeValueMax);\n            }\n            if (i < 0)\n            {\n                throw new ArgumentOutOfRangeException(\"value\", val, SR.RangeValueMin);\n            }\n\n            // Set text\n            Misc.ProxySendMessage(_hwnd, NativeMethods.WM_SETTEXT, IntPtr.Zero, new StringBuilder(i.ToString(CultureInfo.CurrentCulture)));\n        }\n\n        // Request to get the value that this UI element is representing in a native format\n        double IRangeValueProvider.Value\n        {\n            get\n            {\n                string s = WindowsEditBox.Text(_hwnd);\n                if (string.IsNullOrEmpty(s))\n                {\n                    return double.NaN;\n                }\n                return double.Parse(s, CultureInfo.CurrentCulture);\n            }","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsIPAddress.cs#L358-L394","documentation":"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.","triggerScenarios":"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.","commonSituations":"Unclamped arithmetic (e.g. subtracting octets); signed data types from callers; test generators producing negative boundary values.","solutions":["Clamp the value to 0-255 before calling SetValue","Check RangeValuePattern.Minimum (0) before setting","Catch ArgumentOutOfRangeException and validate input at the boundary","Use unsigned/validated sources for octet values"],"exampleFix":"// before\nrangeValue.SetValue(-1);\n// after\nint octet = Math.Clamp(-1, 0, 255);\nrangeValue.SetValue(octet);","handlingStrategy":"validation","validationCode":"int octet = (int)val;\nif (octet < 0) octet = 0; // or reject\nif (octet > 255) octet = 255;","typeGuard":null,"tryCatchPattern":"try { rangeValue.SetValue(val); }\ncatch (ArgumentOutOfRangeException) { /* clamp to 0..255 or reject negative input */ }","preventionTips":["Clamp values with Math.Clamp(v, 0, 255)","Avoid signed arithmetic when computing octets","Check RangeValuePattern.Minimum (0) before setting","Sanitize externally sourced numeric input"],"tags":["uiautomation","argumentoutofrange","rangevalue","min"],"backgroundTag":"value-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}