TechnitiumSoftware/DnsServer · error · InvalidOperationException

Cannot delete record in {} zone.

Error message

Cannot delete record in {} zone.

What it means

Thrown unconditionally by SecondarySubDomainZone.DeleteRecord (single-record). Read-only secondary sub-domain zones reject local deletion with InvalidOperationException; the message uses the parent secondary zone's type name.

Source

Thrown at DnsServerCore/Dns/Zones/SecondarySubDomainZone.cs:58

        }

        #endregion

        #region public

        public override void SetRecords(DnsResourceRecordType type, IReadOnlyList<DnsResourceRecord> records)
        {
            throw new InvalidOperationException("Cannot set records in " + _secondaryZone.GetZoneTypeName() + " zone.");
        }

        public override bool AddRecord(DnsResourceRecord record)
        {
            throw new InvalidOperationException("Cannot add record in " + _secondaryZone.GetZoneTypeName() + " zone.");
        }

        public override bool DeleteRecord(DnsResourceRecordType type, DnsResourceRecordData record)
        {
            throw new InvalidOperationException("Cannot delete record in " + _secondaryZone.GetZoneTypeName() + " zone.");
        }

        public override bool DeleteRecords(DnsResourceRecordType type)
        {
            throw new InvalidOperationException("Cannot delete records in " + _secondaryZone.GetZoneTypeName() + " zone.");
        }

        public override void UpdateRecord(DnsResourceRecord oldRecord, DnsResourceRecord newRecord)
        {
            throw new InvalidOperationException("Cannot update record in " + _secondaryZone.GetZoneTypeName() + " zone.");
        }

        #endregion
    }
}

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Check the zone is not a SecondarySubDomainZone before deleting.
  2. Convert to a primary sub-domain zone if deletions are needed.
  3. Wrap mutation calls in a helper that enforces writability.

Example fix

// before
zone.DeleteRecord(type, rdata);

// after
if (zone is SecondarySubDomainZone)
    return; // read-only
zone.DeleteRecord(type, rdata);
Defensive patterns

Strategy: type-guard

Validate before calling

if (zone is SecondarySubDomainZone)
    return;
zone.DeleteRecord(type, rdata);

Type guard

static bool IsWritable(AuthZone zone) => zone is not SecondarySubDomainZone;

Try / catch

null

Prevention

When it happens

Trigger: Calling subZone.DeleteRecord(type, rdata) on a SecondarySubDomainZone.

Common situations: Generic delete pipelines that target all zones; cleanup routines that do not check writability.

Related errors


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