{"record":{"id":"abb9b6cf5a02ac8a","repo":"TechnitiumSoftware/DnsServer","slug":"failed-to-update-web-server-config-please-try-aga","errorCode":null,"errorMessage":"Failed to update web server config. Please try again.","messagePattern":"Failed to update web server config\\. Please try again\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Apps/BlockPageApp/App.cs","lineNumber":118,"sourceCode":"            await StopAllWebServersAsync();\n\n            Dictionary<string, WebServer> webServers = new Dictionary<string, WebServer>(3);\n            _webServers = webServers;\n\n            if (jsonConfig.ValueKind == JsonValueKind.Array)\n            {\n                bool foundWebServerEnableOnlineCertificateSigning = false;\n\n                foreach (JsonElement jsonWebServerConfig in jsonConfig.EnumerateArray())\n                {\n                    string name = jsonWebServerConfig.GetPropertyValue(\"name\", \"default\");\n\n                    if (!webServers.TryGetValue(name, out WebServer? webServer))\n                    {\n                        webServer = new WebServer(dnsServer, name);\n\n                        if (!webServers.TryAdd(webServer.Name, webServer))\n                            throw new InvalidOperationException(\"Failed to update web server config. Please try again.\");\n                    }\n\n                    await webServer.InitializeAsync(jsonWebServerConfig);\n\n                    foundWebServerEnableOnlineCertificateSigning = jsonWebServerConfig.TryGetProperty(\"webServerEnableOnlineCertificateSigning\", out _);\n                }\n\n                if (!foundWebServerEnableOnlineCertificateSigning)\n                {\n                    config = config.Replace(\"\\\"webServerRootPath\\\"\", \"\\\"webServerEnableOnlineCertificateSigning\\\": false,\\r\\n    \\\"webServerRootPath\\\"\");\n                    await File.WriteAllTextAsync(Path.Combine(dnsServer.ApplicationFolder, \"dnsApp.config\"), config);\n                }\n            }\n            else\n            {\n                WebServer webServer = new WebServer(dnsServer, \"default\");\n                webServers.Add(webServer.Name, webServer);\n","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/Apps/BlockPageApp/App.cs#L100-L136","documentation":"Thrown in the BlockPageApp initializer when adding a freshly created WebServer to the webServers dictionary fails (TryAdd returns false). This happens when the WebServer's resolved Name (which may be normalized/sanitized by the constructor) collides with an existing entry in the config array. InvalidOperationException signals a duplicate or clashing web server name.","triggerScenarios":"Two entries in the web servers config array resolve to the same WebServer.Name (e.g. both default to 'default', or names that sanitize to the same value), so the second TryAdd on the same key fails.","commonSituations":"Duplicate web server objects with the same 'name' (or both missing 'name', defaulting to 'default'); a name containing characters that get sanitized into a collision with another entry.","solutions":["Give every web server entry in the config array a unique 'name'.","Ensure no two entries omit 'name' (they would both become 'default').","Retry the config save after removing the duplicate web server definition."],"exampleFix":"// before (dnsApp.config)\n[ { \"name\": \"default\", ... }, { \"name\": \"default\", ... } ]\n// after\n[ { \"name\": \"default\", ... }, { \"name\": \"internal\", ... } ]","handlingStrategy":"validation","validationCode":"// Ensure unique web server names before constructing WebServer instances.\nvar seen = new HashSet<string>(StringComparer.Ordinal);\nforeach (JsonElement c in jsonConfig.EnumerateArray())\n{\n    string name = c.GetPropertyValue(\"name\", \"default\");\n    if (!seen.Add(name))\n        throw new FormatException($\"Duplicate web server name '{name}' in config; each name must be unique.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give every web server entry a unique 'name'.","Avoid two entries that both default to 'default'.","Sanitize/normalize names consistently so they do not collide after construction."],"tags":["csharp","config","json","duplicate","web-server","technitium","block-page-app"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}