microsoft/aspire · error · ArgumentException
Port range start must be less than or equal to the range…
Error message
Port range start must be less than or equal to the range end.
What it means
Thrown by PortRange.ValidateRange when both endpoints are individually valid ports but rangeStart exceeds rangeEnd, i.e. the range is inverted. Raised as ArgumentException on the start parameter to enforce an ordered, non-empty range.
Solutions
- Swap the values so start <= end.
- Clamp: use start = Math.Min(a, b), end = Math.Max(a, b) when accepting user input.
- Add a startup validation that rejects inverted ranges with a clear config message.
Example fix
// before PortRange.ValidateRange(9000, 8000, nameof(start), nameof(end)); // after PortRange.ValidateRange(8000, 9000, nameof(start), nameof(end));
Defensive patterns
Strategy: validation
Validate before calling
(start, end) = (Math.Min(a, b), Math.Max(a, b)); // normalize before ValidateRange
Try / catch
try { PortRange.ValidateRange(start, end, nameof(start), nameof(end)); }
catch (ArgumentException ex) when (ex.Message.Contains("less than or equal")) { /* swap or fix config */ } Prevention
- Accept ranges as ordered (low, high) and normalize with Min/Max.
- Check env vars aren't swapped when port ranges come from configuration.
- Add a startup assertion that configured ranges are ordered.
When it happens
Trigger: Calling ValidateRange(9000, 8000) — start greater than end — or ranges where config substitution swapped the values (e.g. env vars ASPORT_END set lower than ASPORT_START).
Common situations: Swapped environment variables or config keys for the port range; refactoring that reordered positional arguments to ValidateRange.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Invalid value " " for " ". Expected a port range formatted…
- Port range end must be between
- Port range start must be between
- A BlobServiceClient could not be configured. Ensure valid…
- A BlobServiceClient could not be configured. Ensure valid…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/68de2a9b7c26bf52.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting/Dcp/PortRange.cs:48
/// <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)