{"record":{"id":"5bef39bf0c779495","repo":"dotnet/maui","slug":"the-integer-value-must-be-bounded-with-0-1","errorCode":null,"errorMessage":"The integer value must be bounded with [{0}, {1})","messagePattern":"The integer value must be bounded with \\[(.+?), (.+?)\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs","lineNumber":259,"sourceCode":"\t\t\t\tthrow new ArgumentException(\"The URI must be absolute.\", parameterName);\n\t\t\t}\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Verifies that the specified value is within the expected range.  The assertion fails if it isn't.\n\t\t/// </summary>\n\t\t/// <param name=\"lowerBoundInclusive\">The lower bound inclusive value.</param>\n\t\t/// <param name=\"value\">The value to verify.</param>\n\t\t/// <param name=\"upperBoundExclusive\">The upper bound exclusive value.</param>\n\t\t/// <param name=\"parameterName\">The name of the parameter that caused the current exception.</param>\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive, string parameterName)\n\t\t{\n\t\t\tif (value < lowerBoundInclusive || value >= upperBoundExclusive)\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new ArgumentException(string.Format(CultureInfo.InvariantCulture, \"The integer value must be bounded with [{0}, {1})\", lowerBoundInclusive, upperBoundExclusive), parameterName);\n\t\t\t}\n\t\t}\n\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void BoundedDoubleInc(double lowerBoundInclusive, double value, double upperBoundInclusive, string message, string parameter)\n\t\t{\n\t\t\tif (value < lowerBoundInclusive || value > upperBoundInclusive)\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new ArgumentException(message, parameter);\n\t\t\t}\n\t\t}\n\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void TypeSupportsInterface(Type type, Type interfaceType, string parameterName)\n\t\t{","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs#L241-L277","documentation":"Verify.BoundedInteger throws ArgumentException when value is outside the half-open interval [lowerBoundInclusive, upperBoundExclusive). The message formats both bounds so the caller sees the expected range. It is a range-validation guard for integer parameters.","triggerScenarios":"Calling a method guarded by Verify.BoundedInteger(lo, value, hi, paramName) where value < lo or value >= hi. Common with index, count, DPI, or enumeration-count parameters that must fall within a known valid range.","commonSituations":"Passing a negative index; an enum/count that exceeds the supported maximum; DPI or scaling values outside the supported band; off-by-one confusion between inclusive and exclusive upper bounds.","solutions":["Clamp or validate value before the call: if (value < lo || value >= hi) adjust or reject.","Double-check whether the upper bound is inclusive or exclusive in your own logic.","Use Math.Clamp(value, lo, hi - 1) when a default clamped value is acceptable."],"exampleFix":"// before\nSetColumnIndex(col); // col may be -1 or out of range\n\n// after\nif (col < 0 || col >= columnCount)\n{\n    throw new ArgumentOutOfRangeException(nameof(col));\n}\nSetColumnIndex(col);","handlingStrategy":"validation","validationCode":"// Pre-check: value must be within [lowerBound, upperBound)\nif (value < lowerBoundInclusive || value >= upperBoundExclusive)\n{\n    throw new ArgumentOutOfRangeException(nameof(value), $\"Value must be in [{lowerBoundInclusive}, {upperBoundExclusive}).\");\n}\nSomeApi(value);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate ranges at the call site, paying attention to inclusive vs exclusive bounds.","Use Math.Clamp when a clamped value is acceptable.","Write unit tests for boundary values (lo-1, lo, hi-1, hi)."],"tags":["validation","argument","range","integer","verify"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}