{"record":{"id":"017cd2f2ebb5f50f","repo":"TechnitiumSoftware/DnsServer","slug":"web-service-config-file-format-is-invalid","errorCode":null,"errorMessage":"Web Service config file format is invalid.","messagePattern":"Web Service config file format is invalid\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"critical","filePath":"DnsServerCore/DnsWebService.cs","lineNumber":474,"sourceCode":"                throw new DnsWebServiceException(\"Failed to find 'Administrators' group: auth.config file is probably corrupt.\");\n\n            Group dnsAdmins = _authManager.GetGroup(Group.DNS_ADMINISTRATORS);\n            if (dnsAdmins is null)\n                throw new DnsWebServiceException(\"Failed to find 'DNS Administrators' group: auth.config file is probably corrupt.\");\n\n            foreach (AuthZoneInfo zone in zones)\n            {\n                _authManager.SetPermission(PermissionSection.Zones, zone.Name, admins, PermissionFlag.ViewModifyDelete);\n                _authManager.SetPermission(PermissionSection.Zones, zone.Name, dnsAdmins, PermissionFlag.ViewModifyDelete);\n            }\n\n            _authManager.SaveConfigFile();\n        }\n\n        private void ReadConfigFrom(Stream s)\n        {\n            if (Encoding.ASCII.GetString(s.ReadExactly(2)) != \"WC\") //format\n                throw new InvalidDataException(\"Web Service config file format is invalid.\");\n\n            BinaryReader bR = new BinaryReader(s);\n\n            int version = bR.ReadByte();\n            if (version > 4)\n                throw new InvalidDataException(\"Web Service config version not supported.\");\n\n            _webServiceHttpPort = bR.ReadInt32();\n            _webServiceTlsPort = bR.ReadInt32();\n\n            {\n                IPAddress[] webServiceLocalAddresses;\n\n                int count = bR.ReadByte();\n                if (count > 0)\n                {\n                    IPAddress[] localAddresses = new IPAddress[count];\n","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/DnsWebService.cs#L456-L492","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Confirm the file is a Technitium Web Service config (open it; first two bytes must be 'WC').","Restore the correct webService.config from backup.","If no valid backup exists, remove the file and let the server regenerate defaults on startup, then reconfigure ports/addresses.","Verify the config directory path the service is launched from matches where the real config lives."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"// Verify the Web Service config signature before loading\nusing var fs = File.OpenRead(configPath);\nSpan<byte> magic = stackalloc byte[2];\nif (fs.Read(magic) != 2 || magic[0] != (byte)'W' || magic[1] != (byte)'C')\n    throw new InvalidDataException(\"Not a Technitium Web Service config file.\");","typeGuard":"static bool IsWebServiceConfig(string path)\n{\n    using var fs = File.OpenRead(path);\n    Span<byte> magic = stackalloc byte[2];\n    return fs.Read(magic) == 2 && magic[0] == (byte)'W' && magic[1] == (byte)'C';\n}","tryCatchPattern":"null","preventionTips":["Keep the Web Service config in its default location with a known-good backup.","Do not point the service at arbitrary files in the config folder.","After restores, confirm the 'WC' magic and version byte before starting."],"tags":["dns-server","technitium","configuration","config-file","binary-config","csharp"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}