TechnitiumSoftware/DnsServer · error · DnsServerException
The application name contains an invalid character: {invalid
Error message
The application name contains an invalid character: {invalidChar} What it means
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.
Source
Thrown at DnsServerCore/Dns/Applications/DnsApplicationManager.cs:371
}
catch (Exception ex)
{
_dnsServer.LogManager.Write("DNS Server failed to load DNS application: " + Path.GetFileName(applicationFolder), ex);
}
}));
}
await Task.WhenAll(tasks);
RefreshAppObjectLists();
}
public async Task<DnsApplication> InstallApplicationAsync(string applicationName, Stream appZipStream)
{
foreach (char invalidChar in Path.GetInvalidFileNameChars())
{
if (applicationName.Contains(invalidChar))
throw new DnsServerException("The application name contains an invalid character: " + invalidChar);
}
if (_applications.ContainsKey(applicationName))
throw new DnsServerException("DNS application already exists: " + applicationName);
string applicationFolder = Path.GetFullPath(Path.Combine(_appsPath, applicationName));
if (!applicationFolder.StartsWith(_appsPath + Path.DirectorySeparatorChar))
throw new DnsServerException("The application name is invalid: " + applicationName);
if (Directory.Exists(applicationFolder))
Directory.Delete(applicationFolder, true);
Directory.CreateDirectory(applicationFolder);
//keep a copy of the zip file in the application folder for transferring to other nodes
await using (FileStream zipCopyStream = new FileStream(Path.Combine(applicationFolder, applicationName + ".zip"), FileMode.Create, FileAccess.ReadWrite))
{
await appZipStream.CopyToAsync(zipCopyStream);View on GitHub (pinned to d0484b6c1e)
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.
Example fix
// before
await manager.InstallApplicationAsync(name, zip); // throws on bad char
// after
var invalid = Path.GetInvalidFileNameChars();
if (name.IndexOfAny(invalid) >= 0)
throw new ArgumentException("Invalid application name: " + name);
var safe = string.Concat(name.Select(c => invalid.Contains(c) ? '_' : c));
await manager.InstallApplicationAsync(safe, zip); Defensive patterns
Strategy: validation
Validate before calling
char[] invalid = Path.GetInvalidFileNameChars();
if (name.IndexOfAny(invalid) >= 0)
throw new ArgumentException("Application name contains invalid characters: " + name);
await manager.InstallApplicationAsync(name, zip); Type guard
static bool IsValidApplicationName(string name){
if (string.IsNullOrWhiteSpace(name)) return false;
return name.IndexOfAny(Path.GetInvalidFileNameChars()) < 0;
} Try / catch
try { await manager.InstallApplicationAsync(name, zip); }
catch (DnsServerException ex) when (ex.Message.Contains("invalid character"))
{ name = Sanitize(name); await manager.InstallApplicationAsync(name, zip); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
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
- DNS application already exists: {application.Name}
- Zone transfer TSIG key names cannot have more than 255 entri
- Cluster node URL must use HTTPS scheme.
- The scope name contains an invalid character: {invalidChar}
- DNS application does not exists: {applicationName}
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/56c488ce18c5e528.
Report an issue: GitHub.