TechnitiumSoftware/DnsServer · error · InvalidOperationException

Cannot add record in {} zone.

Error message

Cannot add record in {} zone.

What it means

Thrown unconditionally by SecondarySubDomainZone.AddRecord. Read-only secondary sub-domain zones cannot be mutated locally; InvalidOperationException signals the operation is unsupported. Same rationale as error 595 but for single-record addition.

Source

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

        public SecondarySubDomainZone(SecondaryZone secondaryZone, string name)
            : base(secondaryZone, name)
        {
            _secondaryZone = secondaryZone;
        }

        #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. Guard AddRecord with a zone-type check; skip for SecondarySubDomainZone.
  2. Use a primary sub-domain zone if local authoring is required.
  3. Route all writes through a write-capable check.

Example fix

// before
zone.AddRecord(record);

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

Strategy: type-guard

Validate before calling

if (zone is SecondarySubDomainZone)
    return;
zone.AddRecord(record);

Type guard

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

Try / catch

null

Prevention

When it happens

Trigger: Calling subZone.AddRecord(record) on a SecondarySubDomainZone.

Common situations: Record-import or API-write code paths that assume every zone accepts additions; treating sub-domains as writable caches.

Related errors


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