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

  1. Sanitize the name against Path.GetInvalidFileNameChars before installing.
  2. Restrict names to a safe subset (letters, digits, dash, underscore, dot).
  3. Trim whitespace and reject empty names.
  4. 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

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

Related errors


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