dotnet/maui · error · ArgumentException

The integer value must be bounded with [{0}, {1})

Error message

The integer value must be bounded with [{0}, {1})

What it means

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.

Source

Thrown at src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs:259

				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>
		/// <param name="parameterName">The name of the parameter that caused the current exception.</param>
		[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
		[DebuggerStepThrough]
		public static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive, string parameterName)
		{
			if (value < lowerBoundInclusive || value >= upperBoundExclusive)
			{
				Assert.Fail();
				throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The integer value must be bounded with [{0}, {1})", lowerBoundInclusive, upperBoundExclusive), parameterName);
			}
		}

		[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
		[DebuggerStepThrough]
		public static void BoundedDoubleInc(double lowerBoundInclusive, double value, double upperBoundInclusive, string message, string parameter)
		{
			if (value < lowerBoundInclusive || value > upperBoundInclusive)
			{
				Assert.Fail();
				throw new ArgumentException(message, parameter);
			}
		}

		[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
		[DebuggerStepThrough]
		public static void TypeSupportsInterface(Type type, Type interfaceType, string parameterName)
		{

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Clamp or validate value before the call: if (value < lo || value >= hi) adjust or reject.
  2. Double-check whether the upper bound is inclusive or exclusive in your own logic.
  3. Use Math.Clamp(value, lo, hi - 1) when a default clamped value is acceptable.

Example fix

// before
SetColumnIndex(col); // col may be -1 or out of range

// after
if (col < 0 || col >= columnCount)
{
    throw new ArgumentOutOfRangeException(nameof(col));
}
SetColumnIndex(col);
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check: value must be within [lowerBound, upperBound)
if (value < lowerBoundInclusive || value >= upperBoundExclusive)
{
    throw new ArgumentOutOfRangeException(nameof(value), $"Value must be in [{lowerBoundInclusive}, {upperBoundExclusive}).");
}
SomeApi(value);

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/5bef39bf0c779495. Report an issue: GitHub.