TechnitiumSoftware/DnsServer · error · InvalidOperationException
Cannot set records in {} zone.
Error message
Cannot set records in {} zone. What it means
Thrown unconditionally by SecondarySubDomainZone.SetRecords. A secondary sub-domain zone is read-only (its contents come from zone transfers of the parent secondary zone), so any attempt to author records locally is rejected with InvalidOperationException. The message embeds the parent zone's type name via _secondaryZone.GetZoneTypeName().
Source
Thrown at DnsServerCore/Dns/Zones/SecondarySubDomainZone.cs:48
readonly SecondaryZone _secondaryZone;
#endregion
#region constructor
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)View on GitHub (pinned to d0484b6c1e)
Solutions
- Detect the zone is a SecondarySubDomainZone (read-only) and skip SetRecords.
- If authoring is required, convert the zone to a primary sub-domain zone.
- Centralize record writes behind a guard that checks the zone type.
Example fix
// before
zone.SetRecords(type, records);
// after
if (zone is SecondarySubDomainZone)
throw new InvalidOperationException("zone is read-only; use a primary zone to author records.");
zone.SetRecords(type, records); Defensive patterns
Strategy: type-guard
Validate before calling
if (zone is SecondarySubDomainZone)
throw new InvalidOperationException("Zone is read-only.");
zone.SetRecords(type, records); Type guard
static bool IsWritable(AuthZone zone) => zone is not SecondarySubDomainZone;
Try / catch
null
Prevention
- Route all writes through a writability guard keyed on zone type.
- Document which zone types are read-only in your zone factory.
When it happens
Trigger: Calling subZone.SetRecords(type, records) on a SecondarySubDomainZone instance.
Common situations: Generic zone-management code that calls SetRecords on every zone including sub-domains; migrating a primary sub-domain to secondary without updating write paths.
Related errors
- Cannot add record in {} zone.
- Cannot delete record in {} zone.
- Cannot delete records in {} zone.
- Cannot update record in {} zone.
- Cannot update DNS zone '{zoneInfo.DisplayName}': not a prima
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/ffe130ed4d3fcb71.
Report an issue: GitHub.