{"record":{"id":"ccc0eca2d8dd3544","repo":"TechnitiumSoftware/DnsServer","slug":"reserved-address-must-be-in-scope-range","errorCode":null,"errorMessage":"Reserved address must be in scope range.","messagePattern":"Reserved address must be in scope range\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dhcp/Scope.cs","lineNumber":2179,"sourceCode":"                leases.Sort();\n                return leases;\n            }\n            set\n            {\n                if ((value is null) || (value.Count == 0))\n                {\n                    //remove all DNS entries\n                    foreach (KeyValuePair<ClientIdentifierOption, Lease> entry in _reservedLeases)\n                        _dhcpServer.RemoveDnsEntries(this, entry.Value, true);\n\n                    _reservedLeases.Clear();\n                }\n                else\n                {\n                    foreach (Lease reservedLease in value)\n                    {\n                        if (!IsAddressInRange(reservedLease.Address))\n                            throw new ArgumentOutOfRangeException(nameof(ReservedLeases), \"Reserved address must be in scope range.\");\n                    }\n\n                    //remove DNS entries for reserved leases being removed or has updated domain name\n                    foreach (KeyValuePair<ClientIdentifierOption, Lease> entry in _reservedLeases)\n                    {\n                        Lease existingReservedLease = entry.Value;\n                        bool domainNameMatches = false;\n\n                        foreach (Lease reservedLease in value)\n                        {\n                            if (existingReservedLease.ClientIdentifier.Equals(reservedLease.ClientIdentifier))\n                            {\n                                domainNameMatches = (existingReservedLease.HostName is null) || existingReservedLease.HostName.Equals(reservedLease.HostName, StringComparison.Ordinal);\n                                break;\n                            }\n                        }\n\n                        if (!domainNameMatches)","sourceCodeStart":2161,"sourceCodeEnd":2197,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dhcp/Scope.cs#L2161-L2197","documentation":"Thrown by the ReservedLeases setter when a reserved lease's Address lies outside the scope's start..end range (IsAddressInRange returns false). Reservations must pin an address that belongs to the pool, so an out-of-range reservation is rejected.","triggerScenarios":"Setting scope.ReservedLeases = collection where any reservedLease.Address is below the scope start or above the scope end. Common after ChangeNetwork moves the range without updating reservations.","commonSituations":"Migrating reservations between scopes, stale config after a network change, or reserving the broadcast/network address.","solutions":["Filter reservations so every Address lies within scope.StartingAddress..scope.EndingAddress.","After ChangeNetwork, migrate or drop reservations that fall outside the new range.","Validate reservation addresses in your config layer.","Do not reserve the network or broadcast address."],"exampleFix":"// before\nscope.ReservedLeases = reservations; // may contain out-of-range addresses\n\n// after\nvar inRange = reservations\n    .Where(r => IsInRange(r.Address, scope.StartingAddress, scope.EndingAddress))\n    .ToList();\nscope.ReservedLeases = inRange;","handlingStrategy":"validation","validationCode":"static bool IsInRange(IPAddress a, IPAddress lo, IPAddress hi)\n    => Compare(a, lo) >= 0 && Compare(a, hi) <= 0;\n\nreservations = reservations\n    .Where(r => IsInRange(r.Address, scope.StartingAddress, scope.EndingAddress))\n    .ToList();\nscope.ReservedLeases = reservations;","typeGuard":"static bool ReservationInRange(Lease r, IPAddress lo, IPAddress hi)\n    => IsInRange(r.Address, lo, hi);","tryCatchPattern":"try { scope.ReservedLeases = value; }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"ReservedLeases\")\n{ /* drop out-of-range reservations and retry */ }","preventionTips":["Migrate or drop reservations after ChangeNetwork.","Never reserve the network or broadcast address.","Validate reservation addresses in config before assignment."],"tags":["dhcp","validation","scope","ipv4","reservation","argument"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}