TechnitiumSoftware/DnsServer · error · InvalidOperationException
Cannot add record: use SetRecords() for {type} record
Error message
Cannot add record: use SetRecords() for {type} record What it means
Thrown as InvalidOperationException by PrimaryZone.AddRecord() when the record type is APP. APP records are managed as a complete set, not appended individually, so AddRecord refuses them and points the caller to SetRecords(). This is a programming/usage error.
Source
Thrown at DnsServerCore/Dns/Zones/PrimaryZone.cs:2641
{
switch (record.Type)
{
case DnsResourceRecordType.ANAME:
case DnsResourceRecordType.APP:
throw new DnsServerException("The record type is not supported by DNSSEC signed primary zones.");
default:
if (record.GetAuthGenericRecordInfo().Disabled)
throw new DnsServerException("Cannot add record: disabling records in a signed zones is not supported.");
break;
}
}
switch (record.Type)
{
case DnsResourceRecordType.APP:
throw new InvalidOperationException("Cannot add record: use SetRecords() for " + record.Type.ToString() + " record");
case DnsResourceRecordType.DS:
throw new InvalidOperationException("Cannot set DS record at zone apex.");
case DnsResourceRecordType.DNSKEY:
case DnsResourceRecordType.RRSIG:
case DnsResourceRecordType.NSEC:
case DnsResourceRecordType.NSEC3PARAM:
case DnsResourceRecordType.NSEC3:
throw new InvalidOperationException("Cannot add DNSSEC record.");
case DnsResourceRecordType.FWD:
throw new DnsServerException("The record type is not supported by primary zones.");
default:
if (record.OriginalTtlValue > GetZoneSoaExpire())
throw new DnsServerException("Cannot add record: TTL cannot be greater than SOA EXPIRE.");
View on GitHub (pinned to d0484b6c1e)
Solutions
- Use SetRecords(DnsResourceRecordType.APP, ...) instead of AddRecord to manage APP records as a set.
- Exclude APP from any AddRecord loop.
- Check the record type and route APP to SetRecords.
Example fix
// before
zone.AddRecord(appRecord); // throws: APP needs SetRecords
// after
zone.SetRecords(DnsResourceRecordType.APP, new[] { appRecord }); Defensive patterns
Strategy: type-guard
Validate before calling
if (record.Type == DnsResourceRecordType.APP)
throw new ArgumentException("Use SetRecords() for APP records.");
zone.AddRecord(record); Type guard
static bool IsIndividuallyAddable(DnsResourceRecordType t) =>
t != DnsResourceRecordType.APP; Try / catch
try { zone.AddRecord(record); }
catch (InvalidOperationException ex) when (ex.Message.Contains("use SetRecords()"))
{ Log.Error("Route APP records through SetRecords()."); } Prevention
- Route APP through SetRecords, never AddRecord.
- Exclude set-managed types from AddRecord loops.
- Treat this InvalidOperationException as a caller-side bug.
When it happens
Trigger: Calling AddRecord with a record whose Type is DnsResourceRecordType.APP on a primary zone.
Common situations: Generic record-adding loops that call AddRecord for every record type; attempting to append a single APP record instead of replacing the APP set.
Related errors
- The record type is not supported by DNSSEC signed primary zo
- Cannot set {type} record at zone apex.
- Invalid SOA record.
- Cannot set DNSSEC records.
- Cannot set DS record at zone apex.
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/f1cd64cc7b956bfe.
Report an issue: GitHub.