TechnitiumSoftware/DnsServer · error · InvalidOperationException
Failed to update web server config. Please try again.
Error message
Failed to update web server config. Please try again.
What it means
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.
Source
Thrown at Apps/BlockPageApp/App.cs:118
await StopAllWebServersAsync();
Dictionary<string, WebServer> webServers = new Dictionary<string, WebServer>(3);
_webServers = webServers;
if (jsonConfig.ValueKind == JsonValueKind.Array)
{
bool foundWebServerEnableOnlineCertificateSigning = false;
foreach (JsonElement jsonWebServerConfig in jsonConfig.EnumerateArray())
{
string name = jsonWebServerConfig.GetPropertyValue("name", "default");
if (!webServers.TryGetValue(name, out WebServer? webServer))
{
webServer = new WebServer(dnsServer, name);
if (!webServers.TryAdd(webServer.Name, webServer))
throw new InvalidOperationException("Failed to update web server config. Please try again.");
}
await webServer.InitializeAsync(jsonWebServerConfig);
foundWebServerEnableOnlineCertificateSigning = jsonWebServerConfig.TryGetProperty("webServerEnableOnlineCertificateSigning", out _);
}
if (!foundWebServerEnableOnlineCertificateSigning)
{
config = config.Replace("\"webServerRootPath\"", "\"webServerEnableOnlineCertificateSigning\": false,\r\n \"webServerRootPath\"");
await File.WriteAllTextAsync(Path.Combine(dnsServer.ApplicationFolder, "dnsApp.config"), config);
}
}
else
{
WebServer webServer = new WebServer(dnsServer, "default");
webServers.Add(webServer.Name, webServer);
View on GitHub (pinned to d0484b6c1e)
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.
Example fix
// before (dnsApp.config)
[ { "name": "default", ... }, { "name": "default", ... } ]
// after
[ { "name": "default", ... }, { "name": "internal", ... } ] Defensive patterns
Strategy: validation
Validate before calling
// Ensure unique web server names before constructing WebServer instances.
var seen = new HashSet<string>(StringComparer.Ordinal);
foreach (JsonElement c in jsonConfig.EnumerateArray())
{
string name = c.GetPropertyValue("name", "default");
if (!seen.Add(name))
throw new FormatException($"Duplicate web server name '{name}' in config; each name must be unique.");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 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}
- Network group map contains an invalid network address: {netw
- Groups array was not defined.
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/abb9b6cf5a02ac8a.
Report an issue: GitHub.