TechnitiumSoftware/DnsServer · error · ArgumentOutOfRangeException

Lease time in minutes must be between 0 to 59.

Error message

Lease time in minutes must be between 0 to 59.

What it means

Thrown by the LeaseTimeMinutes setter (byte) when the value exceeds 59. Minutes are a sub-hour component (0..59) of the lease time.

Source

Thrown at DnsServerCore/Dhcp/Scope.cs:1910

        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 OfferDelayTime
        {
            get { return _offerDelayTime; }
            set { _offerDelayTime = value; }
        }

        public bool PingCheckEnabled
        {
            get { return _pingCheckEnabled; }
            set { _pingCheckEnabled = value; }
        }

        public ushort PingCheckTimeout

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Clamp or modulo the value to 0..59 before assignment.
  2. When converting a total-minute figure, carry overflow into hours/days: minutes %= 60; hours += totalMinutes / 60.
  3. Validate config so minutes never exceeds 59.
  4. Confirm the field is minutes, not seconds.

Example fix

// before
scope.LeaseTimeMinutes = (byte)totalMinutes; // throws if > 59

// after
scope.LeaseTimeMinutes = (byte)(totalMinutes % 60);
Defensive patterns

Strategy: validation

Validate before calling

if (minutes > 59) throw new ConfigurationException("LeaseTimeMinutes must be <= 59");
scope.LeaseTimeMinutes = (byte)Math.Clamp(minutes, 0, 59);

Type guard

static bool IsValidLeaseTimeMinutes(int minutes) => minutes >= 0 && minutes <= 59;

Try / catch

try { scope.LeaseTimeMinutes = value; }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "LeaseTimeMinutes")
{ /* clamp and retry */ }

Prevention

When it happens

Trigger: Assigning scope.LeaseTimeMinutes = value where value > 59. Happens when a raw minute count is placed in the minutes field without modular reduction, or a UI omits the bound.

Common situations: Decomposing total minutes incorrectly, deserializing seconds into minutes, or a spinner without a 0..59 cap.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/1d00c41272db0a20. Report an issue: GitHub.