TechnitiumSoftware/DnsServer · error · DnsServerException
Zone was not found for domain: {key}
Error message
Zone was not found for domain: {key} What it means
Thrown by AuthZoneTree.GetOrAddSubDomainZone when the requested domain equals the zone apex (zoneName == domain, case-insensitive) but no AuthZoneNode for that domain exists in the tree, so the GetOrAdd value-factory delegate runs and refuses to fabricate an apex node. It signals that the caller asked for the apex zone itself while only a sub-domain zone can be created on demand. The tree intentionally will not auto-create an apex; it must be registered beforehand.
Source
Thrown at DnsServerCore/Dns/Trees/AuthZoneTree.cs:639
currentKey = value.Key;
}
}
while (true);
}
}
}
return zones;
}
public AuthZone GetOrAddSubDomainZone(string zoneName, string domain, Func<SubDomainZone> valueFactory)
{
bool isApex = zoneName.Equals(domain, StringComparison.OrdinalIgnoreCase);
AuthZoneNode authZoneNode = GetOrAdd(domain, delegate (string key)
{
if (isApex)
throw new DnsServerException("Zone was not found for domain: " + key);
return new AuthZoneNode(valueFactory(), null);
});
if (isApex)
{
if (authZoneNode.ApexZone is null)
throw new DnsServerException("Zone was not found: " + zoneName);
return authZoneNode.ApexZone;
}
else
{
return authZoneNode.GetOrAddParentSideZone(valueFactory);
}
}
public AuthZone GetAuthZone(string zoneName, string domain)View on GitHub (pinned to d0484b6c1e)
Solutions
- Ensure the apex zone is created and registered in the tree (via AuthZoneManager.CreateEmptyApexZone / _root.TryAdd) BEFORE calling GetOrAddSubDomainZone for any apex-equal domain.
- If the apex may legitimately be absent, check with TryGet(zoneName) first and only call GetOrAddSubDomainZone when zoneName != domain.
- Catch DnsServerException and surface a clearer 'apex zone must be created first' error to the upstream caller.
Example fix
// before
var sub = _root.GetOrAddSubDomainZone(zoneName, zoneName, factory);
// after
if (!_root.TryGet(zoneName, out _))
throw new DnsServerException("Apex zone must be created before adding sub-domains: " + zoneName);
var sub = _root.GetOrAddSubDomainZone(zoneName, childDomain, factory); Defensive patterns
Strategy: validation
Validate before calling
// Ensure apex is registered and domain != zoneName before calling sub-domain ops
bool CanGetOrAddSubDomain(AuthZoneTree root, string zoneName, string domain)
{
if (zoneName.Equals(domain, StringComparison.OrdinalIgnoreCase))
return root.TryGet(domain, out var node) && node.ApexZone is not null;
return root.TryGet(zoneName, out _);
} Try / catch
try { return root.GetOrAddSubDomainZone(zoneName, domain, factory); }
catch (DnsServerException ex) when (ex.Message.StartsWith("Zone was not found for domain"))
{
// apex missing — create/retrieve it, then retry or surface upstream
throw new InvalidOperationException("Apex zone not initialized: " + zoneName, ex);
} Prevention
- Always create and register the apex zone before any sub-domain operation.
- Guard sub-domain calls with a TryGet(zoneName) check.
- Treat apex-equal domain arguments to GetOrAddSubDomainZone as a caller bug.
When it happens
Trigger: Calling GetOrAddSubDomainZone(zoneName, domain) with domain equal to zoneName (apex) before the apex zone has been added to the AuthZoneTree via TryAdd/apex registration; the GetOrAdd factory delegate is invoked for the missing domain node and immediately throws because isApex is true.
Common situations: Adding records to a zone whose apex was never created (CreateEmptyApexZone not yet called), misordered zone initialization that creates sub-domains before the apex is registered, or a race where the apex was deleted concurrently with a sub-domain add request.
Related errors
- The domain name '<domain>' does not belong to the zone: <zon
- Zone was not found for domain: <domain>
- 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/ccf3a0f0b30d58d1.
Report an issue: GitHub.