TechnitiumSoftware/DnsServer · error · InvalidDataException
DNS Server config file format is invalid.
Error message
DNS Server config file format is invalid.
What it means
Thrown by ReadConfigFrom when the first two bytes of the configuration stream are not the ASCII magic 'DC'. The server's binary config format starts with a 2-byte signature; a mismatch means the file/stream is not a Technitium DNS Server config.
Source
Thrown at DnsServerCore/Dns/DnsServer.cs:674
if (immediately)
{
SaveConfigFileInternal();
_pendingSave = false;
return;
}
if (_pendingSave)
return;
_pendingSave = true;
_saveTimer.Change(SAVE_TIMER_INITIAL_INTERVAL, Timeout.Infinite);
}
}
private void ReadConfigFrom(Stream s, bool isConfigTransfer)
{
if (Encoding.ASCII.GetString(s.ReadExactly(2)) != "DC") //format
throw new InvalidDataException("DNS Server config file format is invalid.");
BinaryReader bR = new BinaryReader(s);
int version = bR.ReadByte();
if ((version < 1) || (version > 5))
throw new InvalidDataException("DNS Server config version not supported.");
//general
string serverDomain = s.ReadShortString();
if (!isConfigTransfer)
{
try
{
ServerDomain = serverDomain;
}
catch
{
//server domain failed validationView on GitHub (pinned to d0484b6c1e)
Solutions
- Confirm the file is a Technitium DNS Server .scfg/.cfg export and not another format.
- Re-export the config from a working server instance and retry.
- If transferred over HTTP, ensure binary-safe transport (no re-encoding, correct Content-Type).
- Restore from a known-good backup if the file is corrupted.
Defensive patterns
Strategy: validation
Validate before calling
static readonly byte[] Magic = { (byte)'D', (byte)'C' };
bool HasDnsCfgMagic(string path)
{
using var f = File.OpenRead(path);
Span<byte> buf = stackalloc byte[2];
return f.Read(buf) == 2 && buf.SequenceEqual(Magic);
} Type guard
static bool IsDnsServerConfigFile(string path)
{
if (!File.Exists(path)) return false;
using var f = File.OpenRead(path);
Span<byte> b = stackalloc byte[2];
return f.Read(b) == 2 && b[0]=='D' && b[1]=='C';
} Try / catch
try { server.ReadConfigFrom(stream, isConfigTransfer: false); }
catch (InvalidDataException ex) when (ex.Message.Contains("format is invalid")) { return BadRequest("Not a valid DNS Server config file"); } Prevention
- Validate the 'DC' magic before importing.
- Confirm the file came from a Technitium DNS Server export.
- Use binary-safe transfer (no re-encoding) for config files.
When it happens
Trigger: Loading a config file that is actually JSON/text, a different format, truncated, encrypted, or transferred with wrong content-type. Triggered during startup import, config transfer between nodes, or restore from backup.
Common situations: User selects the wrong file in the import UI (e.g. a zone file or app config); a config saved by a newer/incompatible fork; corruption from a partial write or disk full; base64-encoding applied during transfer not decoded.
Related errors
- DNS Server Cluster config file format is invalid.
- DhcpServer scope file format is invalid.
- Local end point group map contains an invalid end point: {lo
- Network group map contains an invalid network address: {netw
- Unexpected URL format: {jsonUrl.ValueKind}
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/713d1fa43eaae7e8.
Report an issue: GitHub.