{"record":{"id":"56c488ce18c5e528","repo":"TechnitiumSoftware/DnsServer","slug":"the-application-name-contains-an-invalid-character","errorCode":null,"errorMessage":"The application name contains an invalid character: {invalidChar}","messagePattern":"The application name contains an invalid character: (.+?)","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/Applications/DnsApplicationManager.cs","lineNumber":371,"sourceCode":"                    }\n                    catch (Exception ex)\n                    {\n                        _dnsServer.LogManager.Write(\"DNS Server failed to load DNS application: \" + Path.GetFileName(applicationFolder), ex);\n                    }\n                }));\n            }\n\n            await Task.WhenAll(tasks);\n\n            RefreshAppObjectLists();\n        }\n\n        public async Task<DnsApplication> InstallApplicationAsync(string applicationName, Stream appZipStream)\n        {\n            foreach (char invalidChar in Path.GetInvalidFileNameChars())\n            {\n                if (applicationName.Contains(invalidChar))\n                    throw new DnsServerException(\"The application name contains an invalid character: \" + invalidChar);\n            }\n\n            if (_applications.ContainsKey(applicationName))\n                throw new DnsServerException(\"DNS application already exists: \" + applicationName);\n\n            string applicationFolder = Path.GetFullPath(Path.Combine(_appsPath, applicationName));\n            if (!applicationFolder.StartsWith(_appsPath + Path.DirectorySeparatorChar))\n                throw new DnsServerException(\"The application name is invalid: \" + applicationName);\n\n            if (Directory.Exists(applicationFolder))\n                Directory.Delete(applicationFolder, true);\n\n            Directory.CreateDirectory(applicationFolder);\n\n            //keep a copy of the zip file in the application folder for transferring to other nodes\n            await using (FileStream zipCopyStream = new FileStream(Path.Combine(applicationFolder, applicationName + \".zip\"), FileMode.Create, FileAccess.ReadWrite))\n            {\n                await appZipStream.CopyToAsync(zipCopyStream);","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/Applications/DnsApplicationManager.cs#L353-L389","documentation":"Thrown by DnsApplicationManager.InstallApplicationAsync when the application name contains a character that is invalid in a file name (per Path.GetInvalidFileNameChars). Because the name becomes a folder on disk, characters like slashes, colons, or wildcards are rejected to prevent path corruption.","triggerScenarios":"Calling InstallApplicationAsync(applicationName, zip) where applicationName contains any of Path.GetInvalidFileNameChars (e.g. '/', '\\\\', ':', '*', '?', '\"', '<', '>', '|') on the current OS. The loop aborts on the first offending character.","commonSituations":"User-typed name with a path separator, a name derived from a URL or label containing a colon/slash, cross-OS porting (Windows rejects more chars than Linux), or templated names injecting symbols.","solutions":["Sanitize the name against Path.GetInvalidFileNameChars before installing.","Restrict names to a safe subset (letters, digits, dash, underscore, dot).","Trim whitespace and reject empty names.","Be aware the invalid set is OS-specific; validate for the deployment target."],"exampleFix":"// before\nawait manager.InstallApplicationAsync(name, zip); // throws on bad char\n\n// after\nvar invalid = Path.GetInvalidFileNameChars();\nif (name.IndexOfAny(invalid) >= 0)\n    throw new ArgumentException(\"Invalid application name: \" + name);\nvar safe = string.Concat(name.Select(c => invalid.Contains(c) ? '_' : c));\nawait manager.InstallApplicationAsync(safe, zip);","handlingStrategy":"validation","validationCode":"char[] invalid = Path.GetInvalidFileNameChars();\nif (name.IndexOfAny(invalid) >= 0)\n    throw new ArgumentException(\"Application name contains invalid characters: \" + name);\nawait manager.InstallApplicationAsync(name, zip);","typeGuard":"static bool IsValidApplicationName(string name){\n    if (string.IsNullOrWhiteSpace(name)) return false;\n    return name.IndexOfAny(Path.GetInvalidFileNameChars()) < 0;\n}","tryCatchPattern":"try { await manager.InstallApplicationAsync(name, zip); }\ncatch (DnsServerException ex) when (ex.Message.Contains(\"invalid character\"))\n{ name = Sanitize(name); await manager.InstallApplicationAsync(name, zip); }","preventionTips":["Restrict application names to [A-Za-z0-9._-].","Validate against Path.GetInvalidFileNameChars for the deployment OS.","Reject empty/whitespace names; never derive names from raw URLs."],"tags":["dns","application","validation","filesystem","security","path"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}