TechnitiumSoftware/DnsServer · error · InvalidDataException
DnsServer blocked zone file format is invalid.
Error message
DnsServer blocked zone file format is invalid.
What it means
Thrown when loading a blocked-zone config file whose first 2 bytes are not the ASCII magic 'BZ'. ReadConfigFrom checks the header before reading the version byte and the zone count; any other content (wrong file, truncation, corruption) is rejected as an invalid blocked-zone format.
Source
Thrown at DnsServerCore/Dns/ZoneManagers/BlockedZoneManager.cs:209
_dnsServer.LogManager.Write("DNS Server blocked zone file was saved: " + blockedZoneFile);
}
public void SaveZoneFile()
{
lock (_saveLock)
{
if (_pendingSave)
return;
_pendingSave = true;
_saveTimer.Change(SAVE_TIMER_INITIAL_INTERVAL, Timeout.Infinite);
}
}
private void ReadConfigFrom(Stream s)
{
if (Encoding.ASCII.GetString(s.ReadExactly(2)) != "BZ") //format
throw new InvalidDataException("DnsServer blocked zone file format is invalid.");
BinaryReader bR = new BinaryReader(s);
byte version = bR.ReadByte();
switch (version)
{
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;View on GitHub (pinned to d0484b6c1e)
Solutions
- Move the bad blocked-zone config aside so the server recreates a valid 'BZ' file on next save.
- Restore the file from a known-good backup if the previously blocked zones matter.
- Verify the correct feature's .bin is in the expected location.
Example fix
// before: blockedZone.bin header != 'BZ' -> blocked-zone load fails // after: remove to regenerate // mv config/blockedZone.bin config/blockedZone.bin.bak (then restart)
Defensive patterns
Strategy: validation
Validate before calling
static bool IsValidBlockedZoneFile(string path)
{
using var fs = File.OpenRead(path);
Span<byte> hdr = stackalloc byte[2];
return fs.Read(hdr) == 2 && hdr[0] == (byte)'B' && hdr[1] == (byte)'Z';
} Try / catch
try { blockedZoneManager.Load(); }
catch (InvalidDataException ex) when (ex.Message.Contains("blocked zone file format"))
{ File.Move(blockedPath, blockedPath + ".bad"); blockedZoneManager.Load(); } Prevention
- Verify the 'BZ' header before loading.
- Keep blocked-zone and block-list files in clearly named paths to avoid swaps.
- Restore backups feature-by-feature, not by dumping all .bin files together.
- Shut the server down cleanly to prevent truncated writes.
When it happens
Trigger: A non-blocked-zone file placed at the blocked-zone config path; truncated/empty file from a crash during write; a 'BL' block-list file mistakenly used here.
Common situations: Restoring backups into the wrong path; partial write left by a power loss; file copied between features by mistake.
Related errors
- DnsServer block list zone file format is invalid.
- DnsServer blocked zone file version not supported.
- CacheZoneManager format is invalid.
- DnsServer block list zone file version not supported.
- CacheZoneManager format version not supported: {version}
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/bf79eb4122d724b8.
Report an issue: GitHub.