TechnitiumSoftware/DnsServer · error · InvalidDataException

DnsServer blocked zone file version not supported.

Error message

DnsServer blocked zone file version not supported.

What it means

Thrown by ReadConfigFrom's version switch default case: the blocked-zone config file has a valid 'BZ' header but its version byte is not '1' (the only supported writer version). Protects against reading a file written by an incompatible (newer) server build.

Source

Thrown at DnsServerCore/Dns/ZoneManagers/BlockedZoneManager.cs:234

                case 1:
                    int length = bR.ReadInt32();
                    int i = 0;

                    AuthZoneManager zoneManager = new AuthZoneManager(_dnsServer);

                    zoneManager.LoadSpecialPrimaryZones(delegate ()
                    {
                        if (i++ < length)
                            return s.ReadShortString();

                        return null;
                    }, _soaRecord, _nsRecord);

                    _zoneManager = zoneManager;
                    break;

                default:
                    throw new InvalidDataException("DnsServer blocked zone file version not supported.");
            }
        }

        private void WriteConfigTo(Stream s)
        {
            IReadOnlyList<AuthZoneInfo> blockedZones = _zoneManager.GetAllZones();
            BinaryWriter bW = new BinaryWriter(s);

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

            bW.Write(blockedZones.Count);

            foreach (AuthZoneInfo zone in blockedZones)
                s.WriteShortString(zone.Name);
        }

        #endregion

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Upgrade the DNS server to a version that supports the file's version.
  2. Delete the blocked-zone config so a fresh version-1 file is regenerated, then reconfigure blocked zones.
  3. Restore from a backup written by the same or older compatible version.

Example fix

// before: blockedZone.bin version = 2 on older server -> throws
// after: discard and regenerate
//   rm config/blockedZone.bin   (re-add blocked zones via UI after restart)
Defensive patterns

Strategy: validation

Validate before calling

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

Try / catch

try { blockedZoneManager.Load(); }
catch (InvalidDataException ex) when (ex.Message.Contains("version not supported"))
{ File.Delete(blockedPath); blockedZoneManager.Load(); }

Prevention

When it happens

Trigger: Downgrading to an older server that cannot read a newer blocked-zone file version; a corrupted/edited version byte; file from a different server generation.

Common situations: Server version rollback; copying config across mismatched versions; byte corruption after the header.

Related errors


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