{"record":{"id":"f7ecc5cfeb6b1d09","repo":"TechnitiumSoftware/DnsServer","slug":"zone-cannot-have-sub-domains","errorCode":null,"errorMessage":"Zone cannot have sub domains.","messagePattern":"Zone cannot have sub domains\\.","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs","lineNumber":766,"sourceCode":"        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        {\n            return _root.GetApexZoneWithSubDomainZones(zoneName);\n        }\n\n        public AuthZoneInfo GetAuthZoneInfo(string zoneName, bool loadHistory = false)\n        {\n            if (_root.TryGet(zoneName, out AuthZoneNode authZoneNode) && (authZoneNode.ApexZone is not null))\n                return new AuthZoneInfo(authZoneNode.ApexZone, loadHistory);\n\n            return null;\n        }\n\n        public AuthZoneInfo FindAuthZoneInfo(string domain, bool loadHistory = false)\n        {","sourceCodeStart":748,"sourceCodeEnd":784,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs#L748-L784","documentation":"Thrown by GetOrAddSubDomainZone when the apex zone's concrete type does not match any of the supported sub-domain-capable classes. The if/else chain handles PrimaryZone, SecondaryCatalogZone, SecondaryZone, CatalogZone and ForwarderZone; every other ApexZone subtype falls through to this throw. In practice the only zone type that reaches here is StubZone, because stub zones only hold NS-delegation hints and cannot authoritatively serve child records.","triggerScenarios":"The resolver requests a name that is a child/sub-domain of an existing Stub zone and the manager attempts GetOrAddSubDomainZone(zoneName, domain) for that zone. A Stub apex zone is found by _root.TryGet, none of the 'is PrimaryZone/Secondary*/CatalogZone/ForwarderZone' branches match, and execution reaches line 766.","commonSituations":"Configuring a Stub zone (AuthZoneType.Stub) for a domain like 'example.com' and then querying or adding records under a delegated child such as 'sub.example.com'. Migrating from a Primary/Secondary zone to a Stub while child delegations still exist. Tooling that auto-creates sub-domain zones from a zone list without filtering Stub zones.","solutions":["Convert the Stub zone to a Primary, Secondary, Forwarder or Catalog zone so it can host sub-domains, using ConvertZoneTypeTo.","Remove the child/delegation records under the Stub zone, or move them into an authoritative parent zone.","Before calling APIs that resolve into sub-domains, check memberZoneInfo.Type/AuthZoneType and skip Stub zones.","If you genuinely need delegation for the child, create a separate authoritative zone for the child name instead of relying on the Stub parent."],"exampleFix":"// before: stub zone cannot host sub-domains\n_root.GetOrAddSubDomainZone(\"example.com\", \"sub.example.com\"); // throws for Stub\n\n// after: ensure the apex is sub-domain-capable\nif (apexZone is StubZone)\n    throw new InvalidOperationException($\"Cannot create sub-domain under stub zone '{zoneName}'; convert to Primary/Secondary/Forwarder first.\");\nreturn _root.GetOrAddSubDomainZone(zoneName, domain);","handlingStrategy":"type-guard","validationCode":"// before GetOrAddSubDomainZone-equivalent logic, ensure the apex is sub-domain-capable\nif (apexZone is StubZone)\n    throw new InvalidOperationException($\"Stub zone '{zoneName}' cannot host sub-domains.\");","typeGuard":"static bool CanHaveSubDomains(ApexZone z) => z is PrimaryZone or SecondaryZone or SecondaryForwarderZone or SecondaryCatalogZone or CatalogZone or ForwarderZone;","tryCatchPattern":null,"preventionTips":["Never rely on a Stub zone to serve child records; keep child delegations in an authoritative parent.","Filter Stub zones out of any workflow that auto-creates sub-domain zones.","Convert Stub zones to Primary/Secondary/Forwarder before delegating children."],"tags":["dns","zone-management","stub-zone","type-mismatch"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}