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
- Ensure the value is strictly less than upper; decrement or clamp to upper - 1 if needed
- If the bound should be inclusive, pass upperInclusive: true (the default)
- Align with the convention of similar APIs (e.g., end-exclusive slicing) and document it
- 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
- Match end-exclusive conventions (Substring/Take-style) consistently across APIs
- Pass upperInclusive: true if callers naturally supply the last valid value
- Add unit tests at boundaries: upper - 1 (valid) and upper (invalid)
- Document exclusivity in XML docs on the validating method
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
- Argument must be greater than or equal to
- Argument must be strictly greater than
- Argument must be less than or equal to
- Argument must be positive or zero (non-negative).
- Argument must be positive.
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)