TechnitiumSoftware/DnsServer · error · DnsServerException

Zone already exists: <zoneInfo.DisplayName>

Error message

Zone already exists: <zoneInfo.DisplayName>

What it means

Thrown by AuthZoneManager.CreateEmptyApexZone when _root.TryAdd(apexZone) returns false, meaning an apex zone with the same name already exists in the tree. The manager refuses to silently overwrite an existing zone and surfaces the conflict, including the zone's display name.

Source

Thrown at DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs:745

                    apexZone = new CatalogZone(_dnsServer, zoneInfo);
                    break;

                case AuthZoneType.SecondaryCatalog:
                    SecondaryCatalogZone secondaryCatalogZone = new SecondaryCatalogZone(_dnsServer, zoneInfo);
                    secondaryCatalogZone.ZoneAdded += SecondaryCatalogZoneAdded;
                    secondaryCatalogZone.ZoneRemoved += SecondaryCatalogZoneRemoved;

                    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)

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Check for an existing zone (GetAuthZoneInfo/TryGet) before adding, or delete the existing zone first.
  2. Make add operations idempotent at the caller: if it exists, update rather than re-add.
  3. Guard concurrent adds with a lock or check-then-add under the same synchronization.

Example fix

// before
zoneManager.AddZone(name, type, ...); // throws if exists

// after
if (zoneManager.GetAuthZoneInfo(name, true) is null)
    zoneManager.AddZone(name, type, ...);
else
    zoneManager.UpdateZone(name, ...);
Defensive patterns

Strategy: validation

Validate before calling

bool ZoneExists(AuthZoneManager mgr, string name) =>
    mgr.GetAuthZoneInfo(name, true) is not null;
// usage:
if (!ZoneExists(mgr, name))
    mgr.AddZone(name, type, ...);

Try / catch

try { zoneManager.AddZone(name, type, ...); }
catch (DnsServerException ex) when (ex.Message.StartsWith("Zone already exists"))
{
    // idempotent: update the existing zone instead
    zoneManager.UpdateZone(name, ...);
}

Prevention

When it happens

Trigger: Calling CreateEmptyApexZone (directly or via AddZone) for a zone name that is already present in the authoritative zone tree — TryAdd fails because the key is taken.

Common situations: Re-adding a zone without deleting it first, a race where two callers add the same zone, importing a zone list with duplicates, or a UI/API retry that double-submits.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/7d4d4edeba723ab0. Report an issue: GitHub.