HandyOrg/HandyControl · error · ArgumentException

The integer value must be bounded with

Error message

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

What it means

Verify.BoundedInteger checks that an integer argument falls within [lowerBoundInclusive, upperBoundExclusive). The library throws ArgumentException with a formatted message naming the expected bounds when the value is outside the range.

Solutions

  1. Clamp or validate the integer before the call: if (v < lo || v >= hi) ...
  2. Use Math.Max(lo, Math.Min(hi - 1, value)) to coerce into range when clamping is acceptable
  3. Fix off-by-one logic at the call site so the value is one below the exclusive upper bound at most

Example fix

// before
VerifyTarget(value: count, lower: 0, upper: items.Count); // count == items.Count throws
// after
if (count < 0 || count >= items.Count) throw new ArgumentOutOfRangeException(nameof(count));
VerifyTarget(value: count, lower: 0, upper: items.Count);
Defensive patterns

Strategy: validation

Validate before calling

if (value < lowerBound || value >= upperBound) throw new ArgumentOutOfRangeException(nameof(value), value, $"Must be in [{lowerBound}, {upperBound})");

Type guard

bool InRange(int v, int lo, int hi) => v >= lo && v < hi;

Try / catch

try { api.Call(value); } catch (ArgumentException ex) when (ex.Message.StartsWith("The integer value must be bounded")) { value = Math.Max(lo, Math.Min(hi - 1, value)); api.Call(value); }

Prevention

When it happens

Trigger: Passing an int to an API backed by Verify.BoundedInteger where value < lowerBoundInclusive or value >= upperBoundExclusive — e.g. negative values where a non-negative count/index is required, or a value equal to the exclusive upper bound.

Common situations: Off-by-one errors (using an exclusive bound as if inclusive), passing -1 or sentinel values as counts, uninitialized/default values of 0 where a positive number is required.

Related errors


AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14). Data as JSON: /api/errors/a45b89b54a529dd5. Report an issue: GitHub.

Appendix: source

Thrown at src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs:180

    [DebuggerStepThrough]
    [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    public static void UriIsAbsolute(Uri uri, string parameterName)
    {
        Verify.IsNotNull<Uri>(uri, parameterName);
        if (!uri.IsAbsoluteUri)
        {
            throw new ArgumentException("The URI must be absolute.", parameterName);
        }
    }

    [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    [DebuggerStepThrough]
    public static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive, string parameterName)
    {
        if (value < lowerBoundInclusive || value >= upperBoundExclusive)
        {
            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The integer value must be bounded with [{0}, {1})", new object[]
            {
                lowerBoundInclusive,
                upperBoundExclusive
            }), parameterName);
        }
    }

    [DebuggerStepThrough]
    [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    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]

View on GitHub (pinned to 2c0875ebd6)