{"record":{"id":"f1c82385e2054e98","repo":"TechnitiumSoftware/DnsServer","slug":"cachezonemanager-format-version-not-supported-ve","errorCode":null,"errorMessage":"CacheZoneManager format version not supported: {version}","messagePattern":"CacheZoneManager format version not supported: (.+?)","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/ZoneManagers/CacheZoneManager.cs","lineNumber":148,"sourceCode":"                            while (bR.BaseStream.Position < bR.BaseStream.Length)\n                            {\n                                CacheZone zone = CacheZone.ReadFrom(bR, serveStale);\n                                if (!zone.IsEmpty)\n                                {\n                                    if (_root.TryAdd(zone.Name, zone))\n                                        addedEntries += zone.TotalEntries;\n                                }\n                            }\n                        }\n                        finally\n                        {\n                            if (addedEntries > 0)\n                                Interlocked.Add(ref _totalEntries, addedEntries);\n                        }\n                        break;\n\n                    default:\n                        throw new InvalidDataException(\"CacheZoneManager format version not supported: \" + version);\n                }\n            }\n\n            _dnsServer.LogManager.Write(\"DNS Cache was loaded from disk successfully.\");\n        }\n\n        public void SaveCacheZoneFile()\n        {\n            _dnsServer.LogManager.Write(\"Saving DNS Cache to disk...\");\n\n            string cacheZoneFile = Path.Combine(_dnsServer.ConfigFolder, \"cache.bin\");\n\n            using (FileStream fS = new FileStream(cacheZoneFile, FileMode.Create, FileAccess.Write))\n            {\n                BinaryWriter bW = new BinaryWriter(fS);\n\n                bW.Write(Encoding.ASCII.GetBytes(\"CZ\")); //format\n                bW.Write((byte)1); //version","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/ZoneManagers/CacheZoneManager.cs#L130-L166","documentation":"Thrown by LoadCacheZoneFile's version switch default case: the cache.bin file has a valid 'CZ' header but its version byte is not '1'. Guards against loading a cache written by an incompatible server version. The offending version number is included in the message.","triggerScenarios":"Downgrading the server to a build that cannot read a newer cache.bin version; a corrupted version byte; cache file from a different server generation copied in.","commonSituations":"Version rollback; migrating config (including cache.bin) between mismatched server builds; corruption.","solutions":["Upgrade the server to a version supporting the file's cache version.","Delete cache.bin and restart; the cache rebuilds naturally (it is not authoritative data).","Avoid copying cache.bin between servers of different versions."],"exampleFix":"// before: cache.bin version = 2 on older server -> throws\n// after: discard (cache is ephemeral)\n//   rm config/cache.bin   (restart; cache warms from live queries)","handlingStrategy":"validation","validationCode":"static int? ReadCacheVersion(string path)\n{\n    using var fs = File.OpenRead(path);\n    Span<byte> hdr = stackalloc byte[3];\n    if (fs.Read(hdr) != 3 || hdr[0] != (byte)'C' || hdr[1] != (byte)'Z') return null;\n    return hdr[2]; // supported == 1\n}","typeGuard":null,"tryCatchPattern":"try { cacheZoneManager.LoadCacheZoneFile(); }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"version not supported\"))\n{ File.Delete(cachePath); cacheZoneManager.LoadCacheZoneFile(); }","preventionTips":["Do not copy cache.bin between servers of different versions.","On downgrade, delete the cache file (it is non-authoritative).","Confirm version compatibility before relying on restored cache.","Treat unknown cache version as discard-and-regenerate."],"tags":["dns","cache","config-file","versioning","serialization"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}