{"record":{"id":"9d6cf66585a7b07e","repo":"TechnitiumSoftware/DnsServer","slug":"the-scope-name-contains-an-invalid-character-inv","errorCode":null,"errorMessage":"The scope name contains an invalid character: {invalidChar}","messagePattern":"The scope name contains an invalid character: (.+?)","errorType":"validation","errorClass":"DhcpServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dhcp/Scope.cs","lineNumber":436,"sourceCode":"            if (_disposed)\n                return;\n\n            _lastAddressOfferedLock?.Dispose();\n\n            _disposed = true;\n            GC.SuppressFinalize(this);\n        }\n\n        #endregion\n\n        #region static\n\n        internal static void ValidateScopeName(string name)\n        {\n            foreach (char invalidChar in Path.GetInvalidFileNameChars())\n            {\n                if (name.Contains(invalidChar))\n                    throw new DhcpServerException(\"The scope name contains an invalid character: \" + invalidChar);\n            }\n        }\n\n        private static bool IsAddressInRange(IPAddress address, IPAddress startingAddress, IPAddress endingAddress)\n        {\n            uint addressNumber = address.ConvertIpToNumber();\n            uint startingAddressNumber = startingAddress.ConvertIpToNumber();\n            uint endingAddressNumber = endingAddress.ConvertIpToNumber();\n\n            return (startingAddressNumber <= addressNumber) && (addressNumber <= endingAddressNumber);\n        }\n\n        private static void ValidateIpv4(IReadOnlyCollection<IPAddress> value, string paramName)\n        {\n            if (value is not null)\n            {\n                foreach (IPAddress ip in value)\n                {","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dhcp/Scope.cs#L418-L454","documentation":"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.","triggerScenarios":"Calling AddScope/RenameScope/ValidateScopeName with a name containing a char from Path.GetInvalidFileNameChars() (e.g. '<', '>', ':', '\"', '/', '\\\\', '|', '?', '*', or control chars; on Windows also others).","commonSituations":"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.","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()."],"exampleFix":"// before\n_dhcpServer.AddScope(new Scope('LAN:office', ...));\n// after\nvar name = new string('LAN:office'.Where(c => !Path.GetInvalidFileNameChars().Contains(c)).ToArray());\n_dhcpServer.AddScope(new Scope(name, ...));","handlingStrategy":"validation","validationCode":"var invalid = new HashSet<char>(Path.GetInvalidFileNameChars());\nif (name.Any(c => invalid.Contains(c))) throw new ArgumentException(\"Scope name has invalid file-name characters\");","typeGuard":"static bool IsValidScopeName(string name) => !string.IsNullOrWhiteSpace(name) && !name.Any(Path.GetInvalidFileNameChars().Contains);","tryCatchPattern":"try { _dhcpServer.RenameScope(old, newName); }\ncatch (DhcpServerException ex) when (ex.Message.Contains(\"invalid character\"))\n{ /* sanitize name: replace bad chars with '-', retry */ }","preventionTips":["Restrict scope names to [A-Za-z0-9_-].","Sanitize user input with Path.GetInvalidFileNameChars filter.","Avoid trailing dots/spaces on Windows."],"tags":["dhcp","scope","validation","filesystem","sanitization"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}