microsoft/aspire · error · ArgumentOutOfRangeException
Must be in the range
Error message
Must be in the range: [{min}{minMessage}, {max}{maxMessage}] What it means
Guard.Range (private helper behind the in-range checks) validates that a value lies within [min, max] and throws ArgumentOutOfRangeException with 'Must be in the range: [{min}{minMessage}, {max}{maxMessage}]'. The optional min/max messages annotate whether bounds are exclusive (e.g. '(0', '0)').
Solutions
- Read the range from the message and clamp/normalize the value into it before the call.
- Validate the value at configuration-load time.
- Fix arithmetic that pushed the value out of range.
- If the caller's range expectation is wrong, adjust the min/max arguments at the check site.
Example fix
// before Guard.ThrowIfNotInRange(percent, 0, 100); // percent == 150 // after percent = Math.Clamp(percent, 0, 100); Guard.ThrowIfNotInRange(percent, 0, 100);
Defensive patterns
Strategy: validation
Validate before calling
if (value < min || value > max) throw new ArgumentOutOfRangeException(nameof(value), value, $"must be in [{min},{max}]"); Try / catch
catch (ArgumentOutOfRangeException ex) { /* clamp ActualValue into the stated range */ } Prevention
- Use Math.Clamp on user/config values.
- Validate ranges at config-load time.
- Note whether bounds are exclusive per the min/max messages.
When it happens
Trigger: Calling any Guard in-range check with a value outside the specified min/max bounds.
Common situations: Config values outside supported bounds (timeout too large, percentage > 100); off-by-one when passing an exclusive bound; unbounded counters growing past a limit.
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
- Must not be negative
- Address prefix must be a string or a parameter resource…
- Address prefix must be omitted, a string, or a parameter…
- Ago must be at least 1 minute to be compatible with acr…
- All resources should be of the same kind when calling…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/b7774f7b1d99c3a3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs:229
}
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void Range<T>(T value, string? paramName, T min, T max, string? minName, string? maxName, string? message)
where T : IComparable<T>
{
if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0)
{
var minMessage = minName != null ? $": {minName}" : string.Empty;
var maxMessage = maxName != null ? $": {maxName}" : string.Empty;
var exMessage = message ?? string.Format(
CultureInfo.InvariantCulture,
"Must be in the range: [{0}{1}, {2}{3}]",
min,
minMessage,
max,
maxMessage);
throw new ArgumentOutOfRangeException(paramName, value, exMessage);
}
}
}
}
View on GitHub (pinned to 25830f84bd)