{"record":{"id":"168e937399cf2c3d","repo":"TechnitiumSoftware/DnsServer","slug":"zone-was-not-found-zonename","errorCode":null,"errorMessage":"Zone was not found: {zoneName}","messagePattern":"Zone was not found: (.+?)","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/Trees/AuthZoneTree.cs","lineNumber":647,"sourceCode":"            return zones;\n        }\n\n        public AuthZone GetOrAddSubDomainZone(string zoneName, string domain, Func<SubDomainZone> valueFactory)\n        {\n            bool isApex = zoneName.Equals(domain, StringComparison.OrdinalIgnoreCase);\n\n            AuthZoneNode authZoneNode = GetOrAdd(domain, delegate (string key)\n            {\n                if (isApex)\n                    throw new DnsServerException(\"Zone was not found for domain: \" + key);\n\n                return new AuthZoneNode(valueFactory(), null);\n            });\n\n            if (isApex)\n            {\n                if (authZoneNode.ApexZone is null)\n                    throw new DnsServerException(\"Zone was not found: \" + zoneName);\n\n                return authZoneNode.ApexZone;\n            }\n            else\n            {\n                return authZoneNode.GetOrAddParentSideZone(valueFactory);\n            }\n        }\n\n        public AuthZone GetAuthZone(string zoneName, string domain)\n        {\n            if (TryGet(domain, out AuthZoneNode authZoneNode))\n                return authZoneNode.GetAuthZone(zoneName);\n\n            return null;\n        }\n\n        public ApexZone GetApexZone(string zoneName)","sourceCodeStart":629,"sourceCodeEnd":665,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/Trees/AuthZoneTree.cs#L629-L665","documentation":"Thrown by AuthZoneTree.GetOrAddSubDomainZone when the apex case (zoneName == domain) is true and the AuthZoneNode for the domain was found/added, but its ApexZone property is null. This means the node exists in the tree without an attached apex zone, which is an inconsistent internal state that the method refuses to return.","triggerScenarios":"GetOrAdd returns an existing AuthZoneNode whose ApexZone field is null — e.g. a node was inserted as a parent-side-only placeholder (new AuthZoneNode(valueFactory(), null) path) and later an apex-equal lookup occurs; or the apex zone was nulled out while the node remained in the tree.","commonSituations":"Concurrent zone teardown that nulls an apex but leaves the node in the tree; partial initialization where a sub-domain node was added with a null parent apex; memory/state corruption from a bug in zone deletion.","solutions":["Verify the apex zone is fully registered (TryGet(zoneName, out ApexZone) succeeds) before invoking sub-domain operations.","Audit zone deletion code to ensure nodes with null ApexZone are removed from the tree, not left behind.","Treat this as an internal-consistency bug: log the zoneName and restart the zone manager if hit."],"exampleFix":"// before\nreturn authZoneNode.ApexZone; // throws if null in apex path\n\n// after (defensive caller)\nif (!_root.TryGet(zoneName, out ApexZone apexZone) || apexZone is null)\n    throw new DnsServerException(\"Apex zone missing or not initialized: \" + zoneName);\nreturn apexZone;","handlingStrategy":"validation","validationCode":"bool ApexReady(AuthZoneTree root, string zoneName)\n    => root.TryGet(zoneName, out var node) && node.ApexZone is not null;","typeGuard":null,"tryCatchPattern":"try { return root.GetOrAddSubDomainZone(zoneName, domain, factory); }\ncatch (DnsServerException ex) when (ex.Message.StartsWith(\"Zone was not found:\"))\n{\n    _log.Error(\"AuthZoneNode exists but ApexZone is null: \" + zoneName);\n    throw;\n}","preventionTips":["Ensure zone deletion removes nodes with null apex from the tree.","Add an invariant check after CreateEmptyApexZone that ApexZone is set.","Log and alert if this internal-consistency error fires."],"tags":["dns","csharp","zone-management","internal-state","technitium"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}