git-ecosystem/git-credential-manager · error · ArgumentOutOfRangeException

Argument must be strictly less than

Error message

Argument must be strictly less than {upper}.

What it means

This ArgumentOutOfRangeException is thrown by EnsureArgument.InRange when upperInclusive is false and the argument is greater than or equal to the upper bound. With an exclusive upper bound the value must satisfy arg < upper strictly. The message interpolates the actual bound.

Solutions

  1. Ensure the value is strictly less than upper; decrement or clamp to upper - 1 if needed
  2. If the bound should be inclusive, pass upperInclusive: true (the default)
  3. Align with the convention of similar APIs (e.g., end-exclusive slicing) and document it
  4. Re-check call sites after changes to the inclusivity flags

Example fix

// before
EnsureArgument.InRange(i, nameof(i), 0, list.Count, upperInclusive: false); // i == list.Count
// after
EnsureArgument.InRange(i, nameof(i), 0, list.Count); // inclusive: i == list.Count - 1 max
Defensive patterns

Strategy: validation

Validate before calling

// exclusive upper bound: value must be < upper
if (value >= upper) value = upper - 1;
EnsureArgument.InRange(value, nameof(value), lower, upper, upperInclusive: false);

Type guard

static bool IsStrictlyBelow(int v, int upper) => v < upper;

Try / catch

try { EnsureArgument.InRange(i, nameof(i), 0, count, upperInclusive: false); }
catch (ArgumentOutOfRangeException ex)
{
    throw new InvalidOperationException($"{ex.ParamName} must be < {count} (exclusive upper bound)", ex);
}

Prevention

When it happens

Trigger: Calling EnsureArgument.InRange(arg, name, lower, upper, upperInclusive: false) with arg >= upper, e.g., passing exactly the exclusive maximum, or using length as an upper bound while the range check treats it as exclusive in a way the caller did not expect.

Common situations: Mixing .NET conventions where some ranges are end-exclusive (Substring, Take) and passing a value equal to the end; boundary values that passed under inclusive checks before a flag change; off-by-one in loop bounds.

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


AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11). Data as JSON: /api/errors/fc06a54a75ee1bd4. Report an issue: GitHub.

Appendix: source

Thrown at src/Core/EnsureArgument.cs:96

        {
            if (lowerInclusive && arg < lower)
            {
                throw new ArgumentOutOfRangeException(name, $"Argument must be greater than or equal to {lower}.");
            }

            if (!lowerInclusive && arg <= lower)
            {
                throw new ArgumentOutOfRangeException(name, $"Argument must be strictly greater than {lower}.");
            }

            if (upperInclusive && arg > upper)
            {
                throw new ArgumentOutOfRangeException(name, $"Argument must be less than or equal to {upper}.");
            }

            if (!upperInclusive && arg >= upper)
            {
                throw new ArgumentOutOfRangeException(name, $"Argument must be strictly less than {upper}.");
            }
        }
    }
}

View on GitHub (pinned to e8ce762cd0)