{"record":{"id":"b1d01356dc6179b1","repo":"TechnitiumSoftware/DnsServer","slug":"no-dynamic-lease-was-found-for-client-identifier","errorCode":null,"errorMessage":"No dynamic lease was found for client identifier: {clientIdentifier}","messagePattern":"No dynamic lease was found for client identifier: (.+?)","errorType":"exception","errorClass":"DhcpServerException","httpStatus":null,"severity":"warning","filePath":"DnsServerCore/Dhcp/Scope.cs","lineNumber":1570,"sourceCode":"\n            foreach (KeyValuePair<ClientIdentifierOption, Lease> entry in _leases)\n            {\n                Lease lease = entry.Value;\n\n                if ((lease.Type == LeaseType.Dynamic) && lease.HardwareAddress.SequenceEqual(hardwareAddressBytes))\n                {\n                    ConvertToReservedLease(lease);\n                    return;\n                }\n            }\n\n            throw new DhcpServerException(\"No dynamic lease was found for hardware address: \" + hardwareAddress);\n        }\n\n        public void ConvertToReservedLease(ClientIdentifierOption clientIdentifier)\n        {\n            if (!_leases.TryGetValue(clientIdentifier, out Lease lease) || (lease.Type != LeaseType.Dynamic))\n                throw new DhcpServerException(\"No dynamic lease was found for client identifier: \" + clientIdentifier.ToString());\n\n            ConvertToReservedLease(lease);\n        }\n\n        public void ConvertToDynamicLease(string hardwareAddress)\n        {\n            byte[] hardwareAddressBytes = Lease.ParseHardwareAddress(hardwareAddress);\n\n            foreach (KeyValuePair<ClientIdentifierOption, Lease> entry in _leases)\n            {\n                Lease lease = entry.Value;\n\n                if ((lease.Type == LeaseType.Reserved) && lease.HardwareAddress.SequenceEqual(hardwareAddressBytes))\n                {\n                    ConvertToDynamicLease(lease);\n                    return;\n                }\n            }","sourceCodeStart":1552,"sourceCodeEnd":1588,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dhcp/Scope.cs#L1552-L1588","documentation":"Thrown by Scope.ConvertToReservedLease(ClientIdentifierOption) when no lease exists for the identifier OR the existing lease is not Dynamic. TryGetValue returning false or lease.Type != LeaseType.Dynamic both raise this DhcpServerException.","triggerScenarios":"Calling scope.ConvertToReservedLease(clientId) for an unknown client identifier, a client whose lease already became Reserved, or an identifier constructed with a mismatched hardware-address type.","commonSituations":"Re-reserving an already-reserved client, converting before the client has obtained a dynamic lease, or identifier byte/type mismatch with stored data.","solutions":["Ensure a Dynamic lease exists for the ClientIdentifierOption on this scope.","Skip the call if the lease is already Reserved.","Create a reservation directly via the reservation API when no dynamic lease exists.","Build the ClientIdentifierOption with the same hardware type as the stored lease."],"exampleFix":"// before\nscope.ConvertToReservedLease(clientId);\n\n// after\nif (scope.Leases.TryGetValue(clientId, out var l) && l.Type == LeaseType.Dynamic)\n    scope.ConvertToReservedLease(clientId);\nelse\n    _log.Info(\"no dynamic lease to convert; add reservation explicitly\");","handlingStrategy":"try-catch","validationCode":"if (!scope.Leases.TryGetValue(clientIdentifier, out var lease) || lease.Type != LeaseType.Dynamic) return;","typeGuard":"static bool HasDynamicLeaseForClient(Scope scope, ClientIdentifierOption id)\n    => scope.Leases.TryGetValue(id, out var l) && l.Type == LeaseType.Dynamic;","tryCatchPattern":"try { scope.ConvertToReservedLease(clientIdentifier); }\ncatch (DhcpServerException ex) when (ex.Message.Contains(\"No dynamic lease\"))\n{ /* lease absent or already reserved; handle accordingly */ }","preventionTips":["Verify lease type is Dynamic before converting.","Use the same hardware-address type when building the identifier.","Make convert actions conditional on current lease state."],"tags":["dhcp","lease","runtime-state","scope","reservation","client-id"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}