TechnitiumSoftware/DnsServer · error · DhcpServerException
Scope with name '{newName}' already exists.
Error message
Scope with name '{newName}' already exists. What it means
RenameScope found the source scope but the target newName is already taken by another scope, so TryAdd(newName, scope) fails. Rename is atomic: it adds the new key before removing the old.
Source
Thrown at DnsServerCore/Dhcp/DhcpServer.cs:1449
}
public Scope GetScope(string name)
{
if (_scopes.TryGetValue(name, out Scope scope))
return scope;
return null;
}
public void RenameScope(string oldName, string newName)
{
Scope.ValidateScopeName(newName);
if (!_scopes.TryGetValue(oldName, out Scope scope))
throw new DhcpServerException("Scope with name '" + oldName + "' does not exists.");
if (!_scopes.TryAdd(newName, scope))
throw new DhcpServerException("Scope with name '" + newName + "' already exists.");
scope.Name = newName;
_scopes.TryRemove(oldName, out _);
SaveScopeFile(scope);
DeleteScopeFile(oldName);
}
public void DeleteScope(string name)
{
if (_scopes.TryGetValue(name, out Scope scope))
{
UnloadScope(scope, true);
DeleteScopeFile(scope.Name);
}
}
public async Task<bool> EnableScopeAsync(string name, bool throwException = false)View on GitHub (pinned to d0484b6c1e)
Solutions
- Choose a newName not currently in use (check GetScope(newName) == null first).
- Rename or delete the conflicting target scope first.
- For a swap, rename through a temporary unique name.
Example fix
// before
_dhcpServer.RenameScope('a', 'b'); // 'b' exists
// after
if (_dhcpServer.GetScope('b') == null) _dhcpServer.RenameScope('a', 'b'); Defensive patterns
Strategy: validation
Validate before calling
if (_dhcpServer.GetScope(newName) != null)
throw new InvalidOperationException($"Scope name '{newName}' already exists"); Type guard
static bool NewNameFree(Func<string, Scope> getScope, string name) => getScope(name) == null;
Try / catch
try { _dhcpServer.RenameScope(oldName, newName); }
catch (DhcpServerException ex) when (ex.Message.Contains("already exists"))
{ /* pick a unique name or delete/swap target, retry */ } Prevention
- Check GetScope(newName) == null before renaming.
- Use a temporary unique name when swapping two scope names.
- Avoid duplicate names across imports.
When it happens
Trigger: Calling RenameScope(oldName, newName) when a different scope already has Name == newName.
Common situations: Renaming onto an existing scope name. UI pre-fill collision. Swapping names without an intermediate.
Related errors
- Scope with same name already exists.
- Scope with overlapping range already exists: {existingScope.
- Scope with name '{oldName}' does not exists.
- The scope name contains an invalid character: {invalidChar}
- The address must be an IPv4 address: {startingAddress}
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/43e8359a295d1152.
Report an issue: GitHub.