TechnitiumSoftware/DnsServer · error · DnsServerException
Zone was not found for domain: <domain>
Error message
Zone was not found for domain: <domain>
What it means
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.
Source
Thrown at DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs:753
apexZone = secondaryCatalogZone;
break;
default:
throw new InvalidDataException("DNS zone type not supported.");
}
if (_root.TryAdd(apexZone))
return apexZone;
throw new DnsServerException("Zone already exists: " + zoneInfo.DisplayName);
}
internal AuthZone GetOrAddSubDomainZone(string zoneName, string domain)
{
return _root.GetOrAddSubDomainZone(zoneName, domain, delegate ()
{
if (!_root.TryGet(zoneName, out ApexZone apexZone))
throw new DnsServerException("Zone was not found for domain: " + domain);
if (apexZone is PrimaryZone primaryZone)
return new PrimarySubDomainZone(primaryZone, domain);
else if (apexZone is SecondaryCatalogZone secondaryCatalogZone)
return new SecondaryCatalogSubDomainZone(secondaryCatalogZone, domain);
else if (apexZone is SecondaryZone secondaryZone)
return new SecondarySubDomainZone(secondaryZone, domain);
else if (apexZone is CatalogZone catalogZone)
return new CatalogSubDomainZone(catalogZone, domain);
else if (apexZone is ForwarderZone forwarderZone)
return new ForwarderSubDomainZone(forwarderZone, domain);
throw new DnsServerException("Zone cannot have sub domains.");
});
}
internal IReadOnlyList<AuthZone> GetApexZoneWithSubDomainZones(string zoneName)
{View on GitHub (pinned to d0484b6c1e)
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.
Example fix
// before
var sub = zoneManager.GetOrAddSubDomainZone(zoneName, subDomain);
// after
if (!zoneManager.ZoneExists(zoneName))
throw new DnsServerException("Create apex zone first: " + zoneName);
var sub = zoneManager.GetOrAddSubDomainZone(zoneName, subDomain); Defensive patterns
Strategy: validation
Validate before calling
bool ApexExists(AuthZoneManager mgr, string zoneName) =>
mgr.GetAuthZoneInfo(zoneName, true) is not null;
// usage:
if (!ApexExists(mgr, zoneName))
throw new InvalidOperationException("Create apex zone first: " + zoneName);
mgr.GetOrAddSubDomainZone(zoneName, subDomain); Try / catch
try { zoneManager.GetOrAddSubDomainZone(zoneName, subDomain); }
catch (DnsServerException ex) when (ex.Message.StartsWith("Zone was not found for domain"))
{
// apex missing — create it, then retry
zoneManager.AddZone(zoneName, AuthZoneType.Primary, ...);
zoneManager.GetOrAddSubDomainZone(zoneName, subDomain);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- Zone was not found for domain: {key}
- The domain name '<domain>' does not belong to the zone: <zon
- Zone was not found: {zoneName}
- DNS zone type not supported.
- Zone already exists: <zoneInfo.DisplayName>
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/ce14bf4abf803dd4.
Report an issue: GitHub.