TechnitiumSoftware/DnsServer · error · InvalidOperationException

Cannot delete records in {} zone.

Error message

Cannot delete records in {} zone.

What it means

Thrown unconditionally by SecondarySubDomainZone.DeleteRecords (RRset). Read-only secondary sub-domain zones reject local RRset deletion with InvalidOperationException. Mirrors errors 595-597 but for the bulk-by-type overload.

Source

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

        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. Skip DeleteRecords for SecondarySubDomainZone instances.
  2. Use a primary sub-domain zone where RRset deletion is required.
  3. Centralize mutations behind an IsReadOnly check.

Example fix

// before
zone.DeleteRecords(type);

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

Strategy: type-guard

Validate before calling

if (zone is SecondarySubDomainZone)
    return;
zone.DeleteRecords(type);

Type guard

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

Try / catch

null

Prevention

When it happens

Trigger: Calling subZone.DeleteRecords(type) on a SecondarySubDomainZone.

Common situations: Bulk-clear routines sweeping all zones; refactoring 'remove all records of type X' logic without a writability guard.

Related errors


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