{"record":{"id":"42e0be8b4bcd4fba","repo":"TechnitiumSoftware/DnsServer","slug":"failed-to-load-dns-zone-file-the-zone-file-does-n","errorCode":null,"errorMessage":"Failed to load DNS zone file: the zone file does not contain any records.","messagePattern":"Failed to load DNS zone file: the zone file does not contain any records\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs","lineNumber":548,"sourceCode":"\n                        return zoneInfo;\n                    }\n\n                case 4:\n                    {\n                        //read zone info\n                        AuthZoneInfo zoneInfo = new AuthZoneInfo(bR, lastModified);\n\n                        //create zone\n                        ApexZone apexZone = CreateEmptyApexZone(zoneInfo);\n                        zoneInfo = new AuthZoneInfo(apexZone);\n\n                        try\n                        {\n                            //read all zone records\n                            DnsResourceRecord[] records = new DnsResourceRecord[bR.ReadInt32()];\n                            if (records.Length < 1)\n                                throw new InvalidDataException(\"Failed to load DNS zone file: the zone file does not contain any records.\");\n\n                            for (int i = 0; i < records.Length; i++)\n                            {\n                                records[i] = new DnsResourceRecord(s);\n                                records[i].Tag = AuthRecordInfo.ReadGenericRecordInfoFrom(bR, records[i].Type);\n                            }\n\n                            //load and init zone\n                            LoadAndInitZone(zoneInfo, records);\n                        }\n                        catch\n                        {\n                            DeleteZone(zoneInfo);\n                            throw;\n                        }\n\n                        return zoneInfo;\n                    }","sourceCodeStart":530,"sourceCodeEnd":566,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs#L530-L566","documentation":"Thrown by AuthZoneManager.LoadZoneFrom in zone-file version 4 (the current format, which serializes AuthZoneInfo and per-record auth info) when the record count read from the stream is less than 1. Version 4 stores the zone info separately and then the record array, so a zero record array is rejected immediately before parsing.","triggerScenarios":"Loading a version-4 zone file whose record-count integer is 0 — empty record list following a valid AuthZoneInfo header.","commonSituations":"A zone saved before any records existed, a truncated/partial write of the record section, or a corrupt count field.","solutions":["Restore from backup or re-create/re-transfer the zone.","Make the writer refuse to persist a zone with zero records, and write atomically (temp + rename).","Validate the record count before invoking LoadZoneFrom."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"bool ZoneV4HasRecords(string path)\n{\n    using var fs = File.OpenRead(path);\n    using var br = new BinaryReader(fs);\n    if (Encoding.ASCII.GetString(br.ReadBytes(2)) != \"DZ\") return false;\n    if (br.ReadByte() != 4) return false;\n    // AuthZoneInfo header length is variable; this check is best done after a full header parse\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try { zoneManager.LoadZoneFrom(fs, lastModified); }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"does not contain any records\"))\n{\n    // v4 zero records — restore backup or re-create/re-transfer\n}","preventionTips":["Refuse to persist a zone with zero records.","Write zone files atomically (temp + rename).","Keep backups and validate record counts before loading."],"tags":["dns","csharp","zone-file","validation","technitium","data-corruption"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}