TechnitiumSoftware/DnsServer · error · DhcpServerException

The scope name contains an invalid character: {invalidChar}

Error message

The scope name contains an invalid character: {invalidChar}

What it means

ValidateScopeName rejects names containing any character in Path.GetInvalidFileNameChars(), because scope names are used as file names on disk. This guards the filesystem against illegal path characters.

Source

Thrown at DnsServerCore/Dhcp/Scope.cs:436

            if (_disposed)
                return;

            _lastAddressOfferedLock?.Dispose();

            _disposed = true;
            GC.SuppressFinalize(this);
        }

        #endregion

        #region static

        internal static void ValidateScopeName(string name)
        {
            foreach (char invalidChar in Path.GetInvalidFileNameChars())
            {
                if (name.Contains(invalidChar))
                    throw new DhcpServerException("The scope name contains an invalid character: " + invalidChar);
            }
        }

        private static bool IsAddressInRange(IPAddress address, IPAddress startingAddress, IPAddress endingAddress)
        {
            uint addressNumber = address.ConvertIpToNumber();
            uint startingAddressNumber = startingAddress.ConvertIpToNumber();
            uint endingAddressNumber = endingAddress.ConvertIpToNumber();

            return (startingAddressNumber <= addressNumber) && (addressNumber <= endingAddressNumber);
        }

        private static void ValidateIpv4(IReadOnlyCollection<IPAddress> value, string paramName)
        {
            if (value is not null)
            {
                foreach (IPAddress ip in value)
                {

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Strip or replace invalid file-name characters from the scope name before adding.
  2. Use only alphanumerics, dashes, and underscores for scope names.
  3. Sanitize with a helper that filters Path.GetInvalidFileNameChars().

Example fix

// before
_dhcpServer.AddScope(new Scope('LAN:office', ...));
// after
var name = new string('LAN:office'.Where(c => !Path.GetInvalidFileNameChars().Contains(c)).ToArray());
_dhcpServer.AddScope(new Scope(name, ...));
Defensive patterns

Strategy: validation

Validate before calling

var invalid = new HashSet<char>(Path.GetInvalidFileNameChars());
if (name.Any(c => invalid.Contains(c))) throw new ArgumentException("Scope name has invalid file-name characters");

Type guard

static bool IsValidScopeName(string name) => !string.IsNullOrWhiteSpace(name) && !name.Any(Path.GetInvalidFileNameChars().Contains);

Try / catch

try { _dhcpServer.RenameScope(old, newName); }
catch (DhcpServerException ex) when (ex.Message.Contains("invalid character"))
{ /* sanitize name: replace bad chars with '-', retry */ }

Prevention

When it happens

Trigger: Calling AddScope/RenameScope/ValidateScopeName with a name containing a char from Path.GetInvalidFileNameChars() (e.g. '<', '>', ':', '"', '/', '\\', '|', '?', '*', or control chars; on Windows also others).

Common situations: User types a descriptive name like 'LAN:office' or 'site<1>'. Importing names from another system with slashes. Names with trailing dots/spaces on Windows.

Understand the failure class

Related errors


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