TechnitiumSoftware/DnsServer · error · InvalidDataException

DNS Server config version not supported.

Error message

DNS Server config version not supported.

What it means

Thrown by DnsWebService.ReadOldConfigFrom() when the legacy binary 'dns.config' file passes the 'DS' magic-byte check but its 1-byte version field falls outside every supported range (currently only version 2-27 and 28-42 are implemented, dispatched to ReadConfigFromV27/ReadConfigFromV42). It is an InvalidDataException (System.IO), signaling that the on-disk config format predates or postdates this build's migration code. The version byte is read via ReadByte() (0-255), so versions 0, 1, and 43-and-above all land in the else branch.

Source

Thrown at DnsServerCore/DnsWebServiceLegacy.cs:151

                            new NetworkAccessControl(IPAddress.Parse("192.168.0.0"), 16),
                            new NetworkAccessControl(IPAddress.Parse("2000::"), 3, true),
                            new NetworkAccessControl(IPAddress.IPv6Any, 0)
                        ];
                }

                _dnsServer.BlockingBypassList = null;
                _dnsServer.BlockingAnswerTtl = 30;
                _dnsServer.ResolverConcurrency = 2;
                _dnsServer.CacheZoneManager.ServeStaleAnswerTtl = CacheZoneManager.SERVE_STALE_ANSWER_TTL;
                _dnsServer.CacheZoneManager.ServeStaleResetTtl = CacheZoneManager.SERVE_STALE_RESET_TTL;
                _dnsServer.ServeStaleMaxWaitTime = DnsServer.SERVE_STALE_MAX_WAIT_TIME;
                _dnsServer.ConcurrentForwarding = true;
                _dnsServer.ResolverLogManager = _log;
                _dnsServer.StatsManager.EnableInMemoryStats = false;
            }
            else
            {
                throw new InvalidDataException("DNS Server config version not supported.");
            }
        }

        private void ReadConfigFromV42(BinaryReader bR, int version)
        {
            //web service
            {
                _webServiceHttpPort = bR.ReadInt32();
                _webServiceTlsPort = bR.ReadInt32();

                {
                    int count = bR.ReadByte();
                    if (count > 0)
                    {
                        IPAddress[] localAddresses = new IPAddress[count];

                        for (int i = 0; i < count; i++)
                            localAddresses[i] = IPAddressExtensions.ReadFrom(bR);

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Upgrade the DNS Server binary to a version equal to or newer than the one that wrote the config (version 43+ files need a 43+-capable build). The forward direction always supports prior versions.
  2. If you must downgrade: move the existing dns.config aside (rename to dns.config.bak) so the server regenerates a fresh v-appropriate config on next start, then re-apply your settings through the web UI/API.
  3. Restore dns.config from a backup taken under a server version this binary supports (<= the version this build's ReadOldConfigFrom can parse).
  4. Verify file integrity: confirm the file starts with 'DS', is not zero-length/truncated, and that the third byte (version) is within 2-42. A corrupt file should be discarded, not force-loaded.

Example fix

// before: older binary opens newer config
using var fs = File.OpenRead(configPath);
webService.TryLoadOldConfigFrom(fs); // throws InvalidDataException "config version not supported"

// after: let the binary write a fresh config for its own version
if (File.Exists(configPath)) File.Move(configPath, configPath + ".bak");
webService.LoadConfigFile(); // regenerates dns.config at the binary's native version
Defensive patterns

Strategy: validation

Validate before calling

// Validate the legacy config before handing it to the parser.
// Supported: 'DS' magic + version byte in [2,42] (2-27 -> V27 reader, 28-42 -> V42 reader).
static bool IsLegacyConfigSupported(string path)
{
    if (!File.Exists(path)) return false;
    using var fs = File.OpenRead(path);
    Span<byte> hdr = stackalloc byte[3];
    if (fs.Read(hdr) < 3) return false;
    if (hdr[0] != (byte)'D' || hdr[1] != (byte)'S') return false;
    int version = hdr[2];
    return version is >= 2 and <= 42;
}

// Usage before load:
string cfg = Path.Combine(configFolder, "dns.config");
if (File.Exists(cfg) && !IsLegacyConfigSupported(cfg))
    File.Move(cfg, cfg + ".bak"); // let the server regenerate a supported config

Type guard

// Narrows a raw byte stream to a known-supported legacy config version.
static bool TryReadSupportedLegacyVersion(BinaryReader bR, out int version)
{
    version = -1;
    if (bR.BaseStream.Length < 3) return false;
    if (bR.ReadByte() != (byte)'D' || bR.ReadByte() != (byte)'S') return false;
    int v = bR.ReadByte();
    if (v is >= 2 and <= 42) { version = v; return true; }
    return false;
}

Try / catch

try
{
    webService.TryLoadOldConfigFrom(stream);
}
catch (InvalidDataException ex) when (ex.Message.Contains("config version not supported"))
{
    // The config is from a newer/older build than this binary can migrate.
    // Back it up and let the server emit a fresh config; do NOT retry with the same bytes.
    log.Warn($"Unsupported legacy config version; regenerating config. Reason: {ex.Message}");
    File.Move(configPath, configPath + ".bak", overwrite: true);
    webService.LoadConfigFile();
}

Prevention

When it happens

Trigger: A dns.config file written by a DNS Server build newer than this binary (version byte >= 43) being opened by an older build — the classic downgrade case. Also: a config from the earliest releases (version 0 or 1, pre-v2), a truncated/corrupted file whose version byte is garbage, or a file that shares the 'DS' header but belongs to a different Technitium product. Through TryLoadOldConfigFile() the exception is caught and logged (returns false), but through TryLoadOldConfigFrom(Stream) or a direct call to ReadOldConfigFrom it propagates to the caller.

Common situations: Rolling back the DNS server binary to an older release while keeping the newer config directory; copying a config folder between machines running mismatched server versions; a half-written dns.config left by a crash mid-save; pointing two different server versions at the same config folder (e.g. a migration dry-run).

Related errors


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