{"record":{"id":"3becfdbe14133d1c","repo":"dotnet/wpf","slug":"sr-valuenotbetweenint32minmax","errorCode":null,"errorMessage":"SR.ValueNotBetweenInt32MinMax","messagePattern":"SR\\.ValueNotBetweenInt32MinMax","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs","lineNumber":5674,"sourceCode":"        }\n\n        /// <summary>\n        /// Validate [Max/Min]Width/Height and Top/Left value.\n        /// </summary>\n        /// Length takes Double; Win32 handles Int.\n        /// We throw exception when the value goes below Int32Min and Int32Max.\n        /// WorkItem 26263: ValidateValueCallback needs to move to PropertyMetadata so Window can\n        /// add its own validation and validate before invalid value is set. Right now, we can only\n        /// validate this in PropertyInalidatinonCallback because of this. (We couldn't make it virtual on\n        /// FrameworkELement because ValidateValueCallback doesn't provide context. Work item 25275).\n        private static void ValidateLengthForHeightWidth(double l)\n        {\n            //basically, NaN and PositiveInfinity are ok, and then anything\n            //that can be converted to Int32\n            if (!Double.IsPositiveInfinity(l) && !double.IsNaN(l) &&\n                ((l > Int32.MaxValue) || (l < Int32.MinValue)))\n            {\n                throw new ArgumentException(SR.Format(SR.ValueNotBetweenInt32MinMax, l));\n            }\n        }\n\n        private static void ValidateTopLeft(double length)\n        {\n            // Values not allowed: PositiveInfinity, NegativeInfinity\n            // and values that are beyond the range of Int32\n            if (Double.IsPositiveInfinity(length) ||\n                Double.IsNegativeInfinity(length))\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidValueForTopLeft, length));\n            }\n\n            if ((length > Int32.MaxValue) ||\n                (length < Int32.MinValue))\n            {\n                throw new ArgumentException(SR.Format(SR.ValueNotBetweenInt32MinMax, length));\n            }","sourceCodeStart":5656,"sourceCodeEnd":5692,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs#L5656-L5692","documentation":"Window validates Left/Top values: NaN and PositiveInfinity are allowed sentinel values, and any finite value must be convertible to Int32. ArgumentException(SR.ValueNotBetweenInt32MinMax) is thrown when a finite double exceeds the Int32 range (l > Int32.MaxValue or l < Int32.MinValue), because window coordinates are ultimately stored as 32-bit pixel values.","triggerScenarios":"Setting Window.Left or Window.Top (or calling the validating setter path) with a finite double outside [-2147483648, 2147483647], e.g. a computed coordinate that overflowed or was parsed from bad data.","commonSituations":"Restoring saved window positions from config with corrupted/huge values; accumulating offsets across loops; data-binding a coordinate to unvalidated numeric input; unit conversion mistakes (twips/DIPs) producing enormous values.","solutions":["Clamp the value into Int32 range before assigning: Math.Max(Int32.MinValue, Math.Min(Int32.MaxValue, value)).","Validate persisted window-position config files for bogus Left/Top values and reset them to defaults when out of range.","Fix the computation producing the oversized value (overflow, wrong units)."],"exampleFix":"// before\nwindow.Left = savedLeft; // may be 1e15\n\n// after\ndouble left = Math.Max(Int32.MinValue, Math.Min(Int32.MaxValue, savedLeft));\nif (!double.IsNaN(left)) window.Left = left;","handlingStrategy":"validation","validationCode":"bool isValidLeft(double l) => double.IsNaN(l) || double.IsPositiveInfinity(l) || (l >= Int32.MinValue && l <= Int32.MaxValue);","typeGuard":"double? SafeCoord(double v) => (double.IsNaN(v) || double.IsPositiveInfinity(v) || (v >= Int32.MinValue && v <= Int32.MaxValue)) ? v : (double?)null;","tryCatchPattern":"try { window.Left = value; }\ncatch (ArgumentException) { window.Left = Double.NaN; /* center/default */ }","preventionTips":["Clamp persisted window coordinates to Int32 range when saving and loading layout.","Check computed coordinates for overflow before assignment.","Use Double.NaN (centered) instead of huge sentinel values."],"tags":["wpf","window","argument-exception","range"],"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"}