TechnitiumSoftware/DnsServer · error · InvalidDataException

Zone does not contain SOA record.

Error message

Zone does not contain SOA record.

What it means

Thrown by AuthZoneManager.LoadZoneFrom in zone-file version 2 when the record count read from the stream is 0. Every DNS zone must contain at least a Start of Authority (SOA) record, so a zero-count record list is invalid before any record is even parsed.

Source

Thrown at DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs:444

                    }
                    break;
            }
        }

        public AuthZoneInfo LoadZoneFrom(Stream s, DateTime lastModified)
        {
            if (Encoding.ASCII.GetString(s.ReadExactly(2)) != "DZ")
                throw new InvalidDataException("DnsServer zone file format is invalid.");

            BinaryReader bR = new BinaryReader(s);

            switch (bR.ReadByte())
            {
                case 2:
                    {
                        DnsResourceRecord[] records = new DnsResourceRecord[bR.ReadInt32()];
                        if (records.Length == 0)
                            throw new InvalidDataException("Zone does not contain SOA record.");

                        DnsResourceRecord soaRecord = null;

                        for (int i = 0; i < records.Length; i++)
                        {
                            records[i] = new DnsResourceRecord(s);

                            if (records[i].Type == DnsResourceRecordType.SOA)
                                soaRecord = records[i];
                        }

                        if (soaRecord == null)
                            throw new InvalidDataException("Zone does not contain SOA record.");

                        //make zone info
                        AuthZoneType zoneType;
                        if (_dnsServer.ServerDomain.Equals((soaRecord.RDATA as DnsSOARecordData).PrimaryNameServer, StringComparison.OrdinalIgnoreCase))
                            zoneType = AuthZoneType.Primary;

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Restore the zone from a backup that contains records, or delete and re-create the zone (primary) or re-transfer (secondary).
  2. Ensure the zone is never persisted with a zero record count — guard the writer or use atomic temp-file + rename.
  3. Validate the zone file (record count > 0) before trusting it.

Example fix

// before
zoneManager.LoadZoneFrom(fs, lastModified); // count==0 throws

// after
using var br = new BinaryReader(fs);
if (Encoding.ASCII.GetString(br.ReadBytes(2)) != "DZ") throw new InvalidDataException("bad magic");
if (br.ReadByte() != 2) throw new InvalidDataException("unsupported version");
int count = br.ReadInt32();
if (count == 0) { /* skip / restore backup */ return; }
fs.Position = 0;
zoneManager.LoadZoneFrom(fs, lastModified);
Defensive patterns

Strategy: validation

Validate before calling

int ZoneV2RecordCount(string path)
{
    using var fs = File.OpenRead(path);
    using var br = new BinaryReader(fs);
    if (Encoding.ASCII.GetString(br.ReadBytes(2)) != "DZ") return -1;
    if (br.ReadByte() != 2) return -1;
    return br.ReadInt32();
}

Try / catch

try { zoneManager.LoadZoneFrom(fs, lastModified); }
catch (InvalidDataException ex) when (ex.Message == "Zone does not contain SOA record.")
{
    // empty zone file — restore from backup or re-create/re-transfer
}

Prevention

When it happens

Trigger: Loading a version-2 zone file whose 4-byte record-count integer is 0 — the file was written empty or its header is corrupt.

Common situations: An empty zone file produced by a failed/cancelled save, a corrupt count field from a partial write, or a hand-crafted/edited binary zone missing its records.

Related errors


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