TechnitiumSoftware/DnsServer · error · ArgumentOutOfRangeException
Lease time in hours must be between 0 to 23.
Error message
Lease time in hours must be between 0 to 23.
What it means
Thrown by the LeaseTimeHours setter (byte) when the value exceeds 23. Hours are a sub-day component of the lease time and must stay within a 24-hour day (0..23).
Source
Thrown at DnsServerCore/Dhcp/Scope.cs:1898
public ushort LeaseTimeDays
{
get { return _leaseTimeDays; }
set
{
if (value > 999)
throw new ArgumentOutOfRangeException(nameof(LeaseTimeDays), "Lease time in days must be between 0 to 999.");
_leaseTimeDays = value;
}
}
public byte LeaseTimeHours
{
get { return _leaseTimeHours; }
set
{
if (value > 23)
throw new ArgumentOutOfRangeException(nameof(LeaseTimeHours), "Lease time in hours must be between 0 to 23.");
_leaseTimeHours = value;
}
}
public byte LeaseTimeMinutes
{
get { return _leaseTimeMinutes; }
set
{
if (value > 59)
throw new ArgumentOutOfRangeException(nameof(LeaseTimeMinutes), "Lease time in minutes must be between 0 to 59.");
_leaseTimeMinutes = value;
}
}
public ushort OfferDelayTimeView on GitHub (pinned to d0484b6c1e)
Solutions
- Clamp to 0..23 before assignment.
- When converting a total-hour figure, set LeaseTimeDays = total / 24 and LeaseTimeHours = total % 24.
- Validate config so hours never exceeds 23.
- Confirm the field is hours, not minutes.
Example fix
// before scope.LeaseTimeHours = (byte)totalHours; // throws if > 23 // after scope.LeaseTimeDays = (ushort)(totalHours / 24); scope.LeaseTimeHours = (byte)(totalHours % 24);
Defensive patterns
Strategy: validation
Validate before calling
if (hours > 23) throw new ConfigurationException("LeaseTimeHours must be <= 23");
scope.LeaseTimeHours = (byte)Math.Clamp(hours, 0, 23); Type guard
static bool IsValidLeaseTimeHours(int hours) => hours >= 0 && hours <= 23;
Try / catch
try { scope.LeaseTimeHours = value; }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "LeaseTimeHours")
{ /* clamp and retry */ } Prevention
- Decompose a total-hour figure into days (n/24) and hours (n%24).
- Bound the hours spinner to 0..23.
- Confirm units: hours, not minutes.
When it happens
Trigger: Assigning scope.LeaseTimeHours = value where value > 23. Happens when a whole-hour count is split into days/hours incorrectly, or a config feeds a raw hour total into the hours field.
Common situations: Decomposing total hours without dividing by 24, UI not bounding the hours spinner, or deserializing a minutes/hours mix-up.
Related errors
- Lease time in days must be between 0 to 999.
- Lease time in minutes must be between 0 to 59.
- Ending address must be greater than starting address.
- Server host name cannot exceed 63 bytes.
- Boot file name cannot exceed 127 bytes.
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/2d0346fab72a47c2.
Report an issue: GitHub.