dotnet/wpf · error · ArgumentException
The integer value must be bounded with
Error message
The integer value must be bounded with [{lowerBoundInclusive}, {upperBoundExclusive}) What it means
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.
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.
Example fix
// before
list.SetRange(0, count); // count == capacity -> throws
// after
if (count >= 0 && count < capacity)
{
list.SetRange(0, count);
} Defensive patterns
Strategy: validation
Validate before calling
if (value < lowerBoundInclusive || value >= upperBoundExclusive)
throw new ArgumentOutOfRangeException(nameof(value), $"Value must be in [{lowerBoundInclusive}, {upperBoundExclusive})"); Type guard
bool InRange(int v, int lo, int hiExcl) => v >= lo && v < hiExcl;
Try / catch
try { api.Call(value); }
catch (ArgumentException ex) when (ex.ParamName == "value") { /* clamp & retry or log */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
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
- ' ' is not a valid value for ' '.
- args
- args
- ArgumentException(message, name)
- ArgumentNullException(name)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/9c21a9faf34bb1b9.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs:235
Verify.IsNotNull(uri, parameterName);
if (!uri.IsAbsoluteUri)
{
throw new ArgumentException("The URI must be absolute.", parameterName);
}
}
/// <summary>
/// Verifies that the specified value is within the expected range. The assertion fails if it isn't.
/// </summary>
/// <param name="lowerBoundInclusive">The lower bound inclusive value.</param>
/// <param name="value">The value to verify.</param>
/// <param name="upperBoundExclusive">The upper bound exclusive value.</param>
[DebuggerStepThrough]
public static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive, string parameterName)
{
if (value < lowerBoundInclusive || value >= upperBoundExclusive)
{
throw new ArgumentException(string.Create(CultureInfo.InvariantCulture, $"The integer value must be bounded with [{lowerBoundInclusive}, {upperBoundExclusive})"), parameterName);
}
}
[DebuggerStepThrough]
public static void BoundedDoubleInc(double lowerBoundInclusive, double value, double upperBoundInclusive, string message, string parameter)
{
if (value < lowerBoundInclusive || value > upperBoundInclusive)
{
throw new ArgumentException(message, parameter);
}
}
[DebuggerStepThrough]
public static void TypeSupportsInterface(Type type, Type interfaceType, string parameterName)
{
Assert.IsNeitherNullNorEmpty(parameterName);
Verify.IsNotNull(type, "type");
Verify.IsNotNull(interfaceType, "interfaceType");View on GitHub (pinned to 81131a70a4)