microsoft/aspire · error · ArgumentOutOfRangeException
Port range end must be between
Error message
Port range end must be between {MinPort} and {MaxPort}. What it means
Thrown by PortRange.ValidateRange when the range end falls outside the valid port interval [MinPort, MaxPort]. Raised as ArgumentOutOfRangeException naming the end parameter, mirroring the start validation.
Solutions
- Set range end to a value between 1 and 65535 inclusive.
- Ensure the end is computed as start + size - 1 with a positive size, then clamped to 65535.
- Validate the configured range with IsValidPort before calling APIs that take a range.
Example fix
// before PortRange.ValidateRange(8000, 0, nameof(start), nameof(end)); // after PortRange.ValidateRange(8000, 8100, nameof(start), nameof(end));
Defensive patterns
Strategy: validation
Validate before calling
if (end is < 1 or > 65535)
throw new ArgumentException($"Port range end {end} must be between 1 and 65535."); Try / catch
try { PortRange.ValidateRange(start, end, nameof(start), nameof(end)); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == nameof(end)) { /* fix configured end */ } Prevention
- Compute end as start + size - 1 and clamp to 65535.
- Validate both endpoints of any user-supplied range before use.
- Document expected range format (start-end, both within 1-65535) in config docs.
When it happens
Trigger: Calling ValidateRange with a rangeEnd < 1 or > 65535, e.g. ValidateRange(8000, 0) or ValidateRange(8000, 70000).
Common situations: Hand-edited port range configuration with an invalid upper bound; computing the end as start+size where size overflowed or was 0/negative leading to an invalid end.
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
- Port range start must be between
- Invalid value " " for " ". Expected a port range formatted…
- Port range start must be less than or equal to the range…
- Random walk offset must be within the configured range size.
- Tunnel expiration must be from 1 hour through 30 days.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/d3f7913bfa0df969.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting/Dcp/PortRange.cs:43
public static bool IsValidPort(int port)
{
return port is >= MinPort and <= MaxPort;
}
/// <summary>
/// Validates that <paramref name="rangeStart"/> and <paramref name="rangeEnd"/> form a valid,
/// non-empty, ordered port range, throwing if not.
/// </summary>
public static void ValidateRange(int rangeStart, int rangeEnd, string rangeStartParamName, string rangeEndParamName)
{
if (!IsValidPort(rangeStart))
{
throw new ArgumentOutOfRangeException(rangeStartParamName, rangeStart, $"Port range start must be between {MinPort} and {MaxPort}.");
}
if (!IsValidPort(rangeEnd))
{
throw new ArgumentOutOfRangeException(rangeEndParamName, rangeEnd, $"Port range end must be between {MinPort} and {MaxPort}.");
}
if (rangeStart > rangeEnd)
{
throw new ArgumentException("Port range start must be less than or equal to the range end.", rangeStartParamName);
}
}
}
View on GitHub (pinned to 25830f84bd)