{"record":{"id":"ce14bf4abf803dd4","repo":"TechnitiumSoftware/DnsServer","slug":"zone-was-not-found-for-domain-domain","errorCode":null,"errorMessage":"Zone was not found for domain: <domain>","messagePattern":"Zone was not found for domain: <domain>","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs","lineNumber":753,"sourceCode":"                    apexZone = secondaryCatalogZone;\n                    break;\n\n                default:\n                    throw new InvalidDataException(\"DNS zone type not supported.\");\n            }\n\n            if (_root.TryAdd(apexZone))\n                return apexZone;\n\n            throw new DnsServerException(\"Zone already exists: \" + zoneInfo.DisplayName);\n        }\n\n        internal AuthZone GetOrAddSubDomainZone(string zoneName, string domain)\n        {\n            return _root.GetOrAddSubDomainZone(zoneName, domain, delegate ()\n            {\n                if (!_root.TryGet(zoneName, out ApexZone apexZone))\n                    throw new DnsServerException(\"Zone was not found for domain: \" + domain);\n\n                if (apexZone is PrimaryZone primaryZone)\n                    return new PrimarySubDomainZone(primaryZone, domain);\n                else if (apexZone is SecondaryCatalogZone secondaryCatalogZone)\n                    return new SecondaryCatalogSubDomainZone(secondaryCatalogZone, domain);\n                else if (apexZone is SecondaryZone secondaryZone)\n                    return new SecondarySubDomainZone(secondaryZone, domain);\n                else if (apexZone is CatalogZone catalogZone)\n                    return new CatalogSubDomainZone(catalogZone, domain);\n                else if (apexZone is ForwarderZone forwarderZone)\n                    return new ForwarderSubDomainZone(forwarderZone, domain);\n\n                throw new DnsServerException(\"Zone cannot have sub domains.\");\n            });\n        }\n\n        internal IReadOnlyList<AuthZone> GetApexZoneWithSubDomainZones(string zoneName)\n        {","sourceCodeStart":735,"sourceCodeEnd":771,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs#L735-L771","documentation":"Thrown inside the value-factory delegate of AuthZoneManager.GetOrAddSubDomainZone when _root.TryGet(zoneName, out ApexZone) fails — i.e. the requested sub-domain zone needs a parent apex zone, but no apex zone with that name exists in the tree. The factory cannot construct a SubDomainZone without a parent, so it aborts.","triggerScenarios":"Calling GetOrAddSubDomainZone(zoneName, domain) where domain is a proper child of zoneName but no apex zone named zoneName has been added to the authoritative tree, triggering the factory delegate.","commonSituations":"Adding records to a sub-domain before its parent apex zone is created, deleting an apex and then serving a still-cached sub-domain request, or a zone-name typo (the apex exists under a different name).","solutions":["Ensure the apex zone exists (create it via AddZone/CreateEmptyApexZone) before requesting sub-domain zones.","Verify with _root.TryGet(zoneName) / GetAuthZoneInfo before calling GetOrAddSubDomainZone.","Double-check the zoneName spelling/casing against the registered apex."],"exampleFix":"// before\nvar sub = zoneManager.GetOrAddSubDomainZone(zoneName, subDomain);\n\n// after\nif (!zoneManager.ZoneExists(zoneName))\n    throw new DnsServerException(\"Create apex zone first: \" + zoneName);\nvar sub = zoneManager.GetOrAddSubDomainZone(zoneName, subDomain);","handlingStrategy":"validation","validationCode":"bool ApexExists(AuthZoneManager mgr, string zoneName) =>\n    mgr.GetAuthZoneInfo(zoneName, true) is not null;\n// usage:\nif (!ApexExists(mgr, zoneName))\n    throw new InvalidOperationException(\"Create apex zone first: \" + zoneName);\nmgr.GetOrAddSubDomainZone(zoneName, subDomain);","typeGuard":null,"tryCatchPattern":"try { zoneManager.GetOrAddSubDomainZone(zoneName, subDomain); }\ncatch (DnsServerException ex) when (ex.Message.StartsWith(\"Zone was not found for domain\"))\n{\n    // apex missing — create it, then retry\n    zoneManager.AddZone(zoneName, AuthZoneType.Primary, ...);\n    zoneManager.GetOrAddSubDomainZone(zoneName, subDomain);\n}","preventionTips":["Create the apex zone before any sub-domain operation.","Verify the apex exists (GetAuthZoneInfo/TryGet) before GetOrAddSubDomainZone.","Double-check zoneName spelling/casing against the registered apex."],"tags":["dns","csharp","zone-management","api-misuse","technitium"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}