{"record":{"id":"e03e970e4bf0d8c5","repo":"TechnitiumSoftware/DnsServer","slug":"no-lease-was-found-for-hardware-address-hardware","errorCode":null,"errorMessage":"No lease was found for hardware address: {hardwareAddress}","messagePattern":"No lease was found for hardware address: (.+?)","errorType":"exception","errorClass":"DhcpServerException","httpStatus":null,"severity":"warning","filePath":"DnsServerCore/Dhcp/Scope.cs","lineNumber":1515,"sourceCode":"                _dhcpServer.RemoveDnsEntries(this, removedLease, true);\n\n                return true;\n            }\n\n            return false;\n        }\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                        {","sourceCodeStart":1497,"sourceCodeEnd":1533,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dhcp/Scope.cs#L1497-L1533","documentation":"Thrown by Scope.RemoveLease(string hardwareAddress) when no existing lease matches the supplied hardware (MAC) address. RemoveLease scans all leases by HardwareAddress and, finding none, raises a DhcpServerException so the caller knows the client was never leased on this scope.","triggerScenarios":"Calling scope.RemoveLease(macString) for a MAC that has no lease: client never obtained an address, lease already expired/removed, MAC formatted differently than stored, or wrong scope object.","commonSituations":"Admin UI 'release lease' action on a stale list, automation retrying a release that already succeeded, MAC passed with dashes when stored with colons, or calling against a scope that doesn't own the client.","solutions":["Verify the MAC string is non-empty and in a parseable format (Lease.ParseHardwareAddress accepts common delimiters).","Confirm a lease for this hardware address actually exists on this scope before calling.","If the release may already be done, treat the exception as benign and ignore/log it.","Make sure you are operating on the scope that issued the lease, not a sibling scope."],"exampleFix":"// before\nscope.RemoveLease(mac); // throws if absent\n\n// after\nbool exists = scope.Leases.Any(l => l.HardwareAddress.SequenceEqual(Lease.ParseHardwareAddress(mac)));\nif (exists) scope.RemoveLease(mac);\nelse _log.Warn($\"no lease for {mac}; nothing to remove\");","handlingStrategy":"validation","validationCode":"byte[] mac = Lease.ParseHardwareAddress(macString);\nbool hasLease = scope.Leases.Any(l => l.HardwareAddress.SequenceEqual(mac));\nif (!hasLease) return; // nothing to remove","typeGuard":"static bool ScopeHasLeaseForHardware(Scope scope, string mac){\n    var bytes = Lease.ParseHardwareAddress(mac);\n    return scope.Leases.Any(l => l.HardwareAddress.SequenceEqual(bytes));\n}","tryCatchPattern":"try { scope.RemoveLease(macString); }\ncatch (DhcpServerException ex) when (ex.Message.Contains(\"No lease was found\"))\n{ /* already released; treat as success */ }","preventionTips":["Refresh your lease listing from the server before offering release actions.","Make release operations idempotent by catching the 'not found' case.","Normalize MAC strings (strip delimiters, lower-case) before comparison."],"tags":["dhcp","lease","runtime-state","scope"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}