{"record":{"id":"b1aefa5e9b541b7a","repo":"TechnitiumSoftware/DnsServer","slug":"no-lease-was-found-for-client-identifier-clienti","errorCode":null,"errorMessage":"No lease was found for client identifier: {clientIdentifier}","messagePattern":"No lease was found for client identifier: (.+?)","errorType":"exception","errorClass":"DhcpServerException","httpStatus":null,"severity":"warning","filePath":"DnsServerCore/Dhcp/Scope.cs","lineNumber":1521,"sourceCode":"        }\n\n        public Lease RemoveLease(string hardwareAddress)\n        {\n            byte[] hardwareAddressBytes = Lease.ParseHardwareAddress(hardwareAddress);\n\n            foreach (KeyValuePair<ClientIdentifierOption, Lease> entry in _leases)\n            {\n                if (entry.Value.HardwareAddress.SequenceEqual(hardwareAddressBytes))\n                    return RemoveLease(entry.Key);\n            }\n\n            throw new DhcpServerException(\"No lease was found for hardware address: \" + hardwareAddress);\n        }\n\n        public Lease RemoveLease(ClientIdentifierOption clientIdentifier)\n        {\n            if (!_leases.TryRemove(clientIdentifier, out Lease removedLease))\n                throw new DhcpServerException(\"No lease was found for client identifier: \" + clientIdentifier.ToString());\n\n            if (removedLease.Type == LeaseType.Reserved)\n            {\n                //remove reserved lease\n                ClientIdentifierOption reservedLeaseClientIdentifier = new ClientIdentifierOption((byte)DhcpMessageHardwareAddressType.Ethernet, removedLease.HardwareAddress);\n                if (_reservedLeases.TryGetValue(reservedLeaseClientIdentifier, out Lease existingReservedLease))\n                {\n                    //remove reserved lease only if the IP addresses match\n                    if (existingReservedLease.Address.Equals(removedLease.Address))\n                    {\n                        if (_reservedLeases.TryRemove(reservedLeaseClientIdentifier, out Lease removedExistingLease))\n                        {\n                            _dhcpServer.RemoveDnsEntries(this, removedLease, true); //remove DNS entries for allocated lease\n                            _dhcpServer.RemoveDnsEntries(this, removedExistingLease, true); //remove DNS entries for reserved lease hostname, if any\n                        }\n                    }\n                }\n            }","sourceCodeStart":1503,"sourceCodeEnd":1539,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dhcp/Scope.cs#L1503-L1539","documentation":"Thrown by Scope.RemoveLease(ClientIdentifierOption) when the concurrent lease dictionary has no entry for the given client identifier (TryRemove returns false). It signals the requested client has no active or reserved lease on this scope.","triggerScenarios":"Calling scope.RemoveLease(clientIdentifier) with a ClientIdentifierOption not present in the leases map: unknown client, expired/already-removed lease, or identifier built with a different hardware-address type than stored.","commonSituations":"Releasing a lease from stale state, retrying a successful release, mismatched DhcpMessageHardwareAddressType in the ClientIdentifierOption, or targeting the wrong scope.","solutions":["Check that a lease for this ClientIdentifierOption exists on the scope before removal.","Ensure the ClientIdentifierOption is constructed with the same hardware-address type and bytes as the stored lease.","If the operation is idempotent in your flow, swallow the DhcpServerException for 'No lease was found'.","Operate on the scope that actually holds the lease."],"exampleFix":"// before\nscope.RemoveLease(clientId); // throws if absent\n\n// after\ntry { scope.RemoveLease(clientId); }\ncatch (DhcpServerException ex) when (ex.Message.Contains(\"No lease was found\"))\n{ _log.Info(\"lease already absent; skipping\"); }","handlingStrategy":"try-catch","validationCode":"if (!scope.Leases.ContainsKey(clientIdentifier)) return; // no lease to remove","typeGuard":"static bool ScopeHasLeaseForClient(Scope scope, ClientIdentifierOption id)\n    => scope.Leases.ContainsKey(id);","tryCatchPattern":"try { scope.RemoveLease(clientIdentifier); }\ncatch (DhcpServerException ex) when (ex.Message.Contains(\"No lease was found\"))\n{ /* idempotent: lease already absent */ }","preventionTips":["Construct ClientIdentifierOption with the same hardware-address type stored on the lease.","Treat remove as idempotent in automation.","Scope the operation to the scope that issued the lease."],"tags":["dhcp","lease","runtime-state","scope","client-id"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}