TechnitiumSoftware/DnsServer · error · DnsServerException

Cannot clone the zone: source zone must be a Primary or Cond

Error message

Cannot clone the zone: source zone must be a Primary or Conditional Forwarder zone.

What it means

Thrown by CloneZone's switch default when sourceZoneInfo.Type is neither Primary nor Forwarder. The clone operation only knows how to reproduce authoritative Primary zones and Conditional Forwarder zones; Secondary, Stub, SecondaryForwarder, Catalog and SecondaryCatalog source types are rejected because their data is non-authoritative or structurally incompatible with a fresh clone.

Source

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

        {
            AuthZoneInfo sourceZoneInfo = GetAuthZoneInfo(sourceZoneName);
            if (sourceZoneInfo is null)
                throw new DnsServerException("No such zone was found: " + (sourceZoneName.Length == 0 ? "." : sourceZoneName));

            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;

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Choose a Primary or Conditional Forwarder zone as the clone source; convert it first if needed.
  2. If you need a copy of a Secondary zone, create a new Secondary zone pointing at the same primary instead of cloning.
  3. Disable/redirect the 'Clone' action in the UI for non-Primary/non-Forwarder zone types.
  4. Pre-validate sourceZoneInfo.Type == AuthZoneType.Primary || == AuthZoneType.Forwarder before calling CloneZone.

Example fix

// before
manager.CloneZone(newName, sourceZone.Name); // source is Secondary -> throws

// after
if (sourceZone.Type != AuthZoneType.Primary && sourceZone.Type != AuthZoneType.Forwarder)
    return BadRequest("Only Primary or Conditional Forwarder zones can be cloned.");
manager.CloneZone(newName, sourceZone.Name);
Defensive patterns

Strategy: validation

Validate before calling

if (source.Type != AuthZoneType.Primary && source.Type != AuthZoneType.Forwarder)
    return BadRequest("Only Primary or Conditional Forwarder zones can be cloned.");

Type guard

static bool IsCloneable(AuthZoneType t) => t is AuthZoneType.Primary or AuthZoneType.Forwarder;

Try / catch

catch (DnsServerException ex) when (ex.Message.Contains("source zone must be")) { return BadRequest(ex.Message); }

Prevention

When it happens

Trigger: Calling CloneZone with a source zone whose AuthZoneType is Secondary, SecondaryForwarder, SecondaryCatalog, Stub, or Catalog. The switch at line 1308 only whitelists AuthZoneType.Primary and AuthZoneType.Forwarder; everything else hits default at line 1318.

Common situations: Trying to duplicate a Secondary zone that is populated by zone transfer from a primary master. Attempting to clone a Catalog zone or a Stub zone. UI that offers 'clone' for every zone type in the list.

Related errors


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