TechnitiumSoftware/DnsServer · error · DhcpServerException
The scope name contains an invalid character
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.
Solutions
- Strip or replace invalid file-name characters from the scope name before adding.
- Use only alphanumerics, dashes, and underscores for scope names.
- 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
- Restrict scope names to [A-Za-z0-9_-].
- Sanitize user input with Path.GetInvalidFileNameChars filter.
- Avoid trailing dots/spaces on Windows.
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
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Boot file name cannot exceed 127 bytes.
- Ending address cannot be same as the broadcast address.
- Ending address must be greater than starting address.
- Exclusion ending address must be in scope range.
- Exclusion starting address must be in scope range.
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/9d6cf66585a7b07e.
Report an issue: GitHub.
Appendix: 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)