{"record":{"id":"47bb6378b0b4cd6e","repo":"TechnitiumSoftware/DnsServer","slug":"no-such-primary-zone-was-found-zonename-47bb63","errorCode":null,"errorMessage":"No such primary zone was found: {zoneName}","messagePattern":"No such primary zone was found: (.+?)","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs","lineNumber":2012,"sourceCode":"            SaveZoneFile(primaryZone.Name);\n        }\n\n        public DnssecPrivateKey UpdatePrimaryZoneDnssecPrivateKey(string zoneName, ushort keyTag, ushort rolloverDays)\n        {\n            if (!_root.TryGet(zoneName, out ApexZone apexZone) || (apexZone is not PrimaryZone primaryZone))\n                throw new DnsServerException(\"No such primary zone was found: \" + zoneName);\n\n            DnssecPrivateKey privateKey = primaryZone.UpdatePrivateKey(keyTag, rolloverDays);\n\n            SaveZoneFile(primaryZone.Name);\n\n            return privateKey;\n        }\n\n        public void DeletePrimaryZoneDnssecPrivateKey(string zoneName, ushort keyTag)\n        {\n            if (!_root.TryGet(zoneName, out ApexZone apexZone) || (apexZone is not PrimaryZone primaryZone))\n                throw new DnsServerException(\"No such primary zone was found: \" + zoneName);\n\n            primaryZone.DeletePrivateKey(keyTag);\n\n            SaveZoneFile(primaryZone.Name);\n        }\n\n        public void PublishAllGeneratedPrimaryZoneDnssecPrivateKeys(string zoneName)\n        {\n            if (!_root.TryGet(zoneName, out ApexZone apexZone) || (apexZone is not PrimaryZone primaryZone))\n                throw new DnsServerException(\"No such primary zone was found: \" + zoneName);\n\n            primaryZone.PublishAllGeneratedKeys();\n\n            SaveZoneFile(primaryZone.Name);\n        }\n\n        public void ActivatePrimaryZoneKskDnsKey(string zoneName, ushort keyTag)\n        {","sourceCodeStart":1994,"sourceCodeEnd":2030,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs#L1994-L2030","documentation":"Thrown by DeletePrimaryZoneDnssecPrivateKey when removing a DNSSEC key by keyTag. The zone must exist and be a PrimaryZone. This is the cleanup path for key lifecycle management; the error indicates the zone prerequisite is unmet before any key deletion logic runs.","triggerScenarios":"Calling DeletePrimaryZoneDnssecPrivateKey(zoneName, keyTag) where the zone is missing or not primary. This can happen during automated key retirement scripts that run after a zone was deleted or re-typed, or when the keyTag belongs to a key on a different zone.","commonSituations":"Post-migration cleanup scripts referencing old zone names; zone deleted but cleanup job still running; attempting to delete a key on a secondary zone (which never owned local keys); stale configuration in an orchestration tool.","solutions":["Check GetAuthZoneInfo(zoneName) for non-null and Type == Primary before attempting deletion.","If the zone was intentionally removed, skip or log the deletion call rather than throwing.","Verify the keyTag belongs to this zone by listing keys first (GetPrimaryZoneDnssecPrivateKeys or equivalent).","Ensure zone file integrity so the zone loads at startup."],"exampleFix":"// before\nauthZoneManager.DeletePrimaryZoneDnssecPrivateKey(\"example.com\", keyTag);\n\n// after\nAuthZoneInfo info = authZoneManager.GetAuthZoneInfo(\"example.com\");\nif (info is null || info.Type != AuthZoneType.Primary)\n{\n    _logger.LogWarning(\"Skipping key deletion: zone '{Zone}' is missing or not primary.\", \"example.com\");\n    return;\n}\nauthZoneManager.DeletePrimaryZoneDnssecPrivateKey(info.Name, keyTag);","handlingStrategy":"validation","validationCode":"AuthZoneInfo info = authZoneManager.GetAuthZoneInfo(zoneName);\nif (info is null || info.Type != AuthZoneType.Primary)\n{\n    logger.LogInformation(\"Skipping key deletion: zone '{Zone}' is not primary.\", zoneName);\n    return;\n}","typeGuard":"static bool IsPrimaryZone(AuthZoneManager mgr, string zoneName)\n    => mgr.GetAuthZoneInfo(zoneName) is { Type: AuthZoneType.Primary };","tryCatchPattern":"try\n{\n    authZoneManager.DeletePrimaryZoneDnssecPrivateKey(zoneName, keyTag);\n}\ncatch (DnsServerException ex) when (ex.Message.StartsWith(\"No such primary zone was found\"))\n{\n    logger.LogInformation(\"Key deletion skipped for '{Zone}': zone gone or not primary.\", zoneName);\n}","preventionTips":["In cleanup scripts, treat 'zone not found' as a successful no-op rather than an error.","Pre-filter zone lists to primary type before bulk key deletion.","Log the zone name and keyTag for audit trails."],"tags":["dnssec","zone-management","primary-zone","validation"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}