{"record":{"id":"9c21a9faf34bb1b9","repo":"dotnet/wpf","slug":"the-integer-value-must-be-bounded-with-lowerboundinclusive","errorCode":null,"errorMessage":"The integer value must be bounded with [{lowerBoundInclusive}, {upperBoundExclusive})","messagePattern":"The integer value must be bounded with \\[(.+?), (.+?)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs","lineNumber":235,"sourceCode":"            Verify.IsNotNull(uri, parameterName);\n            if (!uri.IsAbsoluteUri)\n            {\n                throw new ArgumentException(\"The URI must be absolute.\", parameterName);\n            }\n        }\n\n        /// <summary>\n        /// Verifies that the specified value is within the expected range.  The assertion fails if it isn't.\n        /// </summary>\n        /// <param name=\"lowerBoundInclusive\">The lower bound inclusive value.</param>\n        /// <param name=\"value\">The value to verify.</param>\n        /// <param name=\"upperBoundExclusive\">The upper bound exclusive value.</param>      \n        [DebuggerStepThrough]\n        public static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive, string parameterName)\n        {\n            if (value < lowerBoundInclusive || value >= upperBoundExclusive)\n            {\n                throw new ArgumentException(string.Create(CultureInfo.InvariantCulture, $\"The integer value must be bounded with [{lowerBoundInclusive}, {upperBoundExclusive})\"), parameterName);\n            }\n        }\n        \n        [DebuggerStepThrough]\n        public static void BoundedDoubleInc(double lowerBoundInclusive, double value, double upperBoundInclusive, string message, string parameter)\n        {\n            if (value < lowerBoundInclusive || value > upperBoundInclusive)\n            {\n                throw new ArgumentException(message, parameter);\n            }\n        }\n        \n        [DebuggerStepThrough]\n        public static void TypeSupportsInterface(Type type, Type interfaceType, string parameterName)\n        {\n            Assert.IsNeitherNullNorEmpty(parameterName);\n            Verify.IsNotNull(type, \"type\");\n            Verify.IsNotNull(interfaceType, \"interfaceType\");","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs#L217-L253","documentation":"Verify.BoundedInteger is a WPF internal argument guard that throws ArgumentException when an int parameter falls outside the half-open range [lowerBoundInclusive, upperBoundExclusive). The message embeds the expected bounds and the exception names the offending parameter via parameterName.","triggerScenarios":"Calling any WPF API that internally calls Verify.BoundedInteger and passing a value < lowerBoundInclusive or >= upperBoundExclusive. Because the upper bound is exclusive, passing exactly upperBoundExclusive also throws.","commonSituations":"Off-by-one errors where a caller assumes an inclusive upper bound; passing a 0-based count where a 1-based value is expected; uninitialized (0) or -1 sentinel values passed into range-checked parameters.","solutions":["Clamp or validate the integer against the [lowerBoundInclusive, upperBoundExclusive) range before calling the API.","Check the parameterName in the ArgumentException to identify which argument was out of range.","Fix off-by-one logic: remember the upper bound is exclusive, so the max valid value is upperBoundExclusive - 1."],"exampleFix":"// before\nlist.SetRange(0, count); // count == capacity -> throws\n// after\nif (count >= 0 && count < capacity)\n{\n    list.SetRange(0, count);\n}","handlingStrategy":"validation","validationCode":"if (value < lowerBoundInclusive || value >= upperBoundExclusive)\n    throw new ArgumentOutOfRangeException(nameof(value), $\"Value must be in [{lowerBoundInclusive}, {upperBoundExclusive})\");","typeGuard":"bool InRange(int v, int lo, int hiExcl) => v >= lo && v < hiExcl;","tryCatchPattern":"try { api.Call(value); }\ncatch (ArgumentException ex) when (ex.ParamName == \"value\") { /* clamp & retry or log */ }","preventionTips":["Remember WPF's BoundedInteger upper bound is exclusive.","Clamp user/computed input with Math.Clamp before calling range-checked APIs.","Never pass sentinel values (-1, int.MaxValue) into range-checked parameters."],"tags":["argument-out-of-range","wpf","argument-validation"],"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"}