TechnitiumSoftware/DnsServer · critical · InvalidDataException

Web Service config file format is invalid.

Error message

Web Service config file format is invalid.

What it means

InvalidDataException thrown by DnsWebService.ReadConfigFrom when the first 2 bytes of the Web Service config stream are not the ASCII 'WC' magic. The binary config begins with a 2-char signature used to detect wrong-format or truncated files; any other content is rejected before parsing.

Source

Thrown at DnsServerCore/DnsWebService.cs:474

                throw new DnsWebServiceException("Failed to find 'Administrators' group: auth.config file is probably corrupt.");

            Group dnsAdmins = _authManager.GetGroup(Group.DNS_ADMINISTRATORS);
            if (dnsAdmins is null)
                throw new DnsWebServiceException("Failed to find 'DNS Administrators' group: auth.config file is probably corrupt.");

            foreach (AuthZoneInfo zone in zones)
            {
                _authManager.SetPermission(PermissionSection.Zones, zone.Name, admins, PermissionFlag.ViewModifyDelete);
                _authManager.SetPermission(PermissionSection.Zones, zone.Name, dnsAdmins, PermissionFlag.ViewModifyDelete);
            }

            _authManager.SaveConfigFile();
        }

        private void ReadConfigFrom(Stream s)
        {
            if (Encoding.ASCII.GetString(s.ReadExactly(2)) != "WC") //format
                throw new InvalidDataException("Web Service config file format is invalid.");

            BinaryReader bR = new BinaryReader(s);

            int version = bR.ReadByte();
            if (version > 4)
                throw new InvalidDataException("Web Service config version not supported.");

            _webServiceHttpPort = bR.ReadInt32();
            _webServiceTlsPort = bR.ReadInt32();

            {
                IPAddress[] webServiceLocalAddresses;

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

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Confirm the file is a Technitium Web Service config (open it; first two bytes must be 'WC').
  2. Restore the correct webService.config from backup.
  3. If no valid backup exists, remove the file and let the server regenerate defaults on startup, then reconfigure ports/addresses.
  4. Verify the config directory path the service is launched from matches where the real config lives.

Example fix

null
Defensive patterns

Strategy: validation

Validate before calling

// Verify the Web Service config signature before loading
using var fs = File.OpenRead(configPath);
Span<byte> magic = stackalloc byte[2];
if (fs.Read(magic) != 2 || magic[0] != (byte)'W' || magic[1] != (byte)'C')
    throw new InvalidDataException("Not a Technitium Web Service config file.");

Type guard

static bool IsWebServiceConfig(string path)
{
    using var fs = File.OpenRead(path);
    Span<byte> magic = stackalloc byte[2];
    return fs.Read(magic) == 2 && magic[0] == (byte)'W' && magic[1] == (byte)'C';
}

Try / catch

null

Prevention

When it happens

Trigger: Pointing the Web Service at a config file that is not a Technitium Web Service config (e.g. a dnsServer.config, a text file, an auth.config, or a zero-byte file). Triggered at startup or config load when ReadConfigFrom is invoked.

Common situations: Wrong file passed as config path; restore from backup pulled the wrong file; file overwritten by another tool; downgrade/upgrade mixed file formats; empty file from a failed prior write.

Related errors


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