TechnitiumSoftware/DnsServer · error · InvalidDataException

CacheZoneManager format version not supported: {version}

Error message

CacheZoneManager format version not supported: {version}

What it means

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.

Source

Thrown at DnsServerCore/Dns/ZoneManagers/CacheZoneManager.cs:148

                            while (bR.BaseStream.Position < bR.BaseStream.Length)
                            {
                                CacheZone zone = CacheZone.ReadFrom(bR, serveStale);
                                if (!zone.IsEmpty)
                                {
                                    if (_root.TryAdd(zone.Name, zone))
                                        addedEntries += zone.TotalEntries;
                                }
                            }
                        }
                        finally
                        {
                            if (addedEntries > 0)
                                Interlocked.Add(ref _totalEntries, addedEntries);
                        }
                        break;

                    default:
                        throw new InvalidDataException("CacheZoneManager format version not supported: " + version);
                }
            }

            _dnsServer.LogManager.Write("DNS Cache was loaded from disk successfully.");
        }

        public void SaveCacheZoneFile()
        {
            _dnsServer.LogManager.Write("Saving DNS Cache to disk...");

            string cacheZoneFile = Path.Combine(_dnsServer.ConfigFolder, "cache.bin");

            using (FileStream fS = new FileStream(cacheZoneFile, FileMode.Create, FileAccess.Write))
            {
                BinaryWriter bW = new BinaryWriter(fS);

                bW.Write(Encoding.ASCII.GetBytes("CZ")); //format
                bW.Write((byte)1); //version

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Upgrade the server to a version supporting the file's cache version.
  2. Delete cache.bin and restart; the cache rebuilds naturally (it is not authoritative data).
  3. Avoid copying cache.bin between servers of different versions.

Example fix

// before: cache.bin version = 2 on older server -> throws
// after: discard (cache is ephemeral)
//   rm config/cache.bin   (restart; cache warms from live queries)
Defensive patterns

Strategy: validation

Validate before calling

static int? ReadCacheVersion(string path)
{
    using var fs = File.OpenRead(path);
    Span<byte> hdr = stackalloc byte[3];
    if (fs.Read(hdr) != 3 || hdr[0] != (byte)'C' || hdr[1] != (byte)'Z') return null;
    return hdr[2]; // supported == 1
}

Try / catch

try { cacheZoneManager.LoadCacheZoneFile(); }
catch (InvalidDataException ex) when (ex.Message.Contains("version not supported"))
{ File.Delete(cachePath); cacheZoneManager.LoadCacheZoneFile(); }

Prevention

When it happens

Trigger: 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.

Common situations: Version rollback; migrating config (including cache.bin) between mismatched server builds; corruption.

Related errors


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