TechnitiumSoftware/DnsServer · error · ArgumentOutOfRangeException

Exclusion ending address must be in scope range.

Error message

Exclusion ending address must be in scope range.

What it means

Thrown by the Exclusions setter when an exclusion's EndingAddress falls outside the scope's start..end range (IsAddressInRange returns false). Like the starting-address check, the exclusion end must be a real pool address.

Source

Thrown at DnsServerCore/Dhcp/Scope.cs:2144

        public IReadOnlyCollection<Exclusion> Exclusions
        {
            get { return _exclusions; }
            set
            {
                if (value is null)
                {
                    _exclusions = null;
                }
                else
                {
                    foreach (Exclusion exclusion in value)
                    {
                        if (!IsAddressInRange(exclusion.StartingAddress))
                            throw new ArgumentOutOfRangeException(nameof(Exclusions), "Exclusion starting address must be in scope range.");

                        if (!IsAddressInRange(exclusion.EndingAddress))
                            throw new ArgumentOutOfRangeException(nameof(Exclusions), "Exclusion ending address must be in scope range.");
                    }

                    _exclusions = value;
                }
            }
        }

        public IReadOnlyCollection<Lease> ReservedLeases
        {
            get
            {
                List<Lease> leases = new List<Lease>(_reservedLeases.Count);

                foreach (KeyValuePair<ClientIdentifierOption, Lease> entry in _reservedLeases)
                    leases.Add(entry.Value);

                leases.Sort();
                return leases;

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Filter exclusions so every EndingAddress lies within the scope range.
  2. Avoid using the broadcast or network address as an exclusion bound.
  3. Rebuild exclusions after ChangeNetwork.
  4. Validate exclusion end bounds in config before assignment.

Example fix

// before
scope.Exclusions = rawExclusions;

// after
var inRange = rawExclusions
    .Where(e => IsInRange(e.StartingAddress, scope.StartingAddress, scope.EndingAddress)
             && IsInRange(e.EndingAddress, scope.StartingAddress, scope.EndingAddress))
    .ToList();
scope.Exclusions = inRange;
Defensive patterns

Strategy: validation

Validate before calling

static bool IsInRange(IPAddress a, IPAddress lo, IPAddress hi)
    => Compare(a, lo) >= 0 && Compare(a, hi) <= 0;

exclusions = exclusions
    .Where(e => IsInRange(e.StartingAddress, scope.StartingAddress, scope.EndingAddress)
             && IsInRange(e.EndingAddress, scope.StartingAddress, scope.EndingAddress))
    .ToList();
scope.Exclusions = exclusions;

Type guard

static bool ExclusionEndInRange(Exclusion e, IPAddress lo, IPAddress hi)
    => IsInRange(e.EndingAddress, lo, hi);

Try / catch

try { scope.Exclusions = value; }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "Exclusions" && ex.Message.Contains("ending address"))
{ /* filter exclusions and retry */ }

Prevention

When it happens

Trigger: Setting scope.Exclusions = collection where any exclusion.EndingAddress is outside scope.StartingAddress..scope.EndingAddress. Common when an exclusion end equals the broadcast or a host beyond the pool.

Common situations: Exclusion end set to the broadcast address (which is outside the pool), stale exclusions after ChangeNetwork, or copy-paste from a larger scope.

Related errors


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