TechnitiumSoftware/DnsServer · error · ArgumentOutOfRangeException

Lease time in days must be between 0 to 999.

Error message

Lease time in days must be between 0 to 999.

What it means

Thrown by the LeaseTimeDays setter (ushort) when the value exceeds 999. The lease time is serialized/stored with a 3-digit cap, so values above 999 days are rejected as out of the supported range.

Source

Thrown at DnsServerCore/Dhcp/Scope.cs:1886

        public bool Enabled
        { get { return _enabled; } }

        public IPAddress StartingAddress
        { get { return _startingAddress; } }

        public IPAddress EndingAddress
        { get { return _endingAddress; } }

        public IPAddress SubnetMask
        { get { return _subnetMask; } }

        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

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Clamp the input to the 0..999 range before assignment.
  2. Reject or warn on values above 999 in your config validation layer.
  3. If a longer lease is genuinely needed, note the library hard-caps at 999 days.
  4. Double-check units: the field is days, not seconds or hours.

Example fix

// before
scope.LeaseTimeDays = (ushort)configDays; // throws if > 999

// after
scope.LeaseTimeDays = (ushort)Math.Min(configDays, 999);
Defensive patterns

Strategy: validation

Validate before calling

if (days > 999) throw new ConfigurationException("LeaseTimeDays must be <= 999");
scope.LeaseTimeDays = (ushort)Math.Clamp(days, 0, 999);

Type guard

static bool IsValidLeaseTimeDays(int days) => days >= 0 && days <= 999;

Try / catch

try { scope.LeaseTimeDays = value; }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "LeaseTimeDays")
{ /* clamp and retry, or report to user */ }

Prevention

When it happens

Trigger: Assigning scope.LeaseTimeDays = value where value > 999. Common with config deserialization feeding an unchecked integer, or a UI allowing thousands of days.

Common situations: Importing a config with a huge lease lifetime, unit confusion (passing seconds/days), or a slider without an upper bound.

Related errors


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