TechnitiumSoftware/DnsServer · error · DnsServerException

Failed to clone the zone: zone already exists.

Error message

Failed to clone the zone: zone already exists.

What it means

Thrown by CloneZone when the new-zone creation step (CreatePrimaryZone or CreateForwarderZone) returns null. Inside this library, those create methods return null specifically when a zone with the target name already exists, so this message names that condition. It fires after the source-type switch succeeds but before any options are copied.

Source

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

            AuthZoneInfo zoneInfo;

            switch (sourceZoneInfo.Type)
            {
                case AuthZoneType.Primary:
                    zoneInfo = CreatePrimaryZone(zoneName);
                    break;

                case AuthZoneType.Forwarder:
                    zoneInfo = CreateForwarderZone(zoneName);
                    break;

                default:
                    throw new DnsServerException("Cannot clone the zone: source zone must be a Primary or Conditional Forwarder zone.");
            }

            if (zoneInfo is null)
                throw new DnsServerException("Failed to clone the zone: zone already exists.");

            //copy zone options
            zoneInfo.Disabled = sourceZoneInfo.Disabled;

            if (zoneInfo.Type == AuthZoneType.Primary)
            {
                zoneInfo.ZoneTransfer = sourceZoneInfo.ZoneTransfer;
                zoneInfo.ZoneTransferNetworkACL = sourceZoneInfo.ZoneTransferNetworkACL;
                zoneInfo.ZoneTransferTsigKeyNames = sourceZoneInfo.ZoneTransferTsigKeyNames;

                zoneInfo.Notify = sourceZoneInfo.Notify;
                zoneInfo.NotifyNameServers = sourceZoneInfo.NotifyNameServers;

                zoneInfo.Update = sourceZoneInfo.Update;
                zoneInfo.UpdateNetworkACL = sourceZoneInfo.UpdateNetworkACL;

                if (sourceZoneInfo.UpdateSecurityPolicies is not null)
                {

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Pick a unique zoneName for the clone target, or delete the existing target zone first.
  2. Pre-check with GetAuthZoneInfo(zoneName); if non-null, prompt the user to overwrite or rename.
  3. Use a timestamped or counter-suffixed name generator for clone targets.
  4. Make the clone operation idempotent by checking existence before invoking CloneZone.

Example fix

// before
manager.CloneZone("copy.example.com", sourceZoneName); // throws if target exists

// after
string target = "copy.example.com";
while (manager.GetAuthZoneInfo(target) is not null)
    target = "copy-" + Guid.NewGuid().ToString("n").Substring(0,4) + ".example.com";
manager.CloneZone(target, sourceZoneName);
Defensive patterns

Strategy: validation

Validate before calling

if (manager.GetAuthZoneInfo(targetName) is not null)
    return Conflict($"Target zone '{targetName}' already exists.");

Try / catch

catch (DnsServerException ex) when (ex.Message.Contains("already exists")) { return Conflict(ex.Message); }

Prevention

When it happens

Trigger: Calling CloneZone(zoneName, sourceZoneName) where zoneName already matches an existing authoritative zone. CreatePrimaryZone/CreateForwarderZone detect the duplicate via _root.TryAdd returning false and yield null, which the null-check at line 1322 turns into this exception.

Common situations: Re-running a clone script without deleting the prior target. UI auto-generating the clone name as '<source>-copy' which already exists. Cloning the same source twice in a loop.

Related errors


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