TechnitiumSoftware/DnsServer · error · DhcpServerException

Scope with same name already exists.

Error message

Scope with same name already exists.

What it means

The new scope's Name already exists in the concurrent scopes dictionary, so TryAdd fails. Names are the unique key for scopes.

Source

Thrown at DnsServerCore/Dhcp/DhcpServer.cs:1235

                if (throwException)
                    throw;
            }

            return false;
        }

        private async Task LoadScopeAsync(Scope scope, bool waitForInterface)
        {
            foreach (KeyValuePair<string, Scope> entry in _scopes)
            {
                Scope existingScope = entry.Value;

                if (existingScope.IsAddressInRange(scope.StartingAddress) || existingScope.IsAddressInRange(scope.EndingAddress))
                    throw new DhcpServerException("Scope with overlapping range already exists: " + existingScope.StartingAddress.ToString() + "-" + existingScope.EndingAddress.ToString());
            }

            if (!_scopes.TryAdd(scope.Name, scope))
                throw new DhcpServerException("Scope with same name already exists.");

            if (scope.Enabled)
            {
                if (!await ActivateScopeAsync(scope, waitForInterface))
                    scope.SetEnabled(false);
            }

            _log.Write("DHCP Server successfully loaded scope: " + scope.Name);
        }

        private void UnloadScope(Scope scope, bool removeDnsEntries)
        {
            if (scope.Enabled)
                DeactivateScope(scope, removeDnsEntries, false);

            if (_scopes.TryRemove(scope.Name, out Scope removedScope))
            {
                removedScope.Dispose();

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Pick a unique scope Name before adding.
  2. Delete the existing scope with the same name first, or rename it.
  3. Remove duplicate scope files from the scopes directory.

Example fix

// before
_dhcpServer.AddScope(new Scope('lan', ...)); // 'lan' already exists
// after
_dhcpServer.DeleteScope('lan');
_dhcpServer.AddScope(new Scope('lan', ...));
Defensive patterns

Strategy: validation

Validate before calling

if (_dhcpServer.GetScope(scope.Name) != null)
    throw new InvalidOperationException($"Scope name '{scope.Name}' already exists");

Type guard

static bool ScopeNameFree(Func<string, Scope> getScope, string name) => getScope(name) == null;

Try / catch

try { await _dhcpServer.LoadScopeAsync(scope, true); }
catch (DhcpServerException ex) when (ex.Message.Contains("same name already exists"))
{ /* rename or delete existing scope, retry */ }

Prevention

When it happens

Trigger: Loading/adding a scope whose Name equals an already-loaded scope's Name; `_scopes.TryAdd(scope.Name, scope)` returns false.

Common situations: Duplicate scope file in the scopes directory. Renaming then re-adding without deleting the old. Race where two scope files share a name.

Related errors


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