TechnitiumSoftware/DnsServer · error · InvalidDomainNameException

Invalid domain name [ ]: invalid character [ ] was found.

Error message

Invalid domain name [{domain}]: invalid character [{labelChar}] was found.

What it means

Thrown by DomainTree.ConvertToByteKey when a character in a label has a code point value greater than or equal to the size of the internal _keyMap lookup table. The library's character map only covers a limited ASCII-ish range, so any character whose int value falls outside that range (e.g. high Unicode codepoints or characters beyond the table) cannot be mapped to a key byte. Only thrown when throwException is true.

Solutions

  1. Encode internationalized domain names with IdnMapping.GetAscii (Punycode) before passing them to the tree.
  2. Sanitize names to the allowed DNS character set [a-zA-Z0-9-._*] at ingestion.
  3. Probe with throwException=false to obtain null for unmappable characters.

Example fix

// before
_tree.GetOrAdd("café.example.com", value);

// after
var idn = new System.Globalization.IdnMapping();
string ascii = idn.GetAscii(domain);
_tree.GetOrAdd(ascii, value);
Defensive patterns

Strategy: validation

Validate before calling

string ToAsciiDomain(string d)
{
    var idn = new System.Globalization.IdnMapping();
    try { return idn.GetAscii(d); } catch { return null; }
}

Type guard

static bool IsAsciiDomain(string d) =>
    d.Length > 0 && d.All(c => (int)c < KEYMAP_SIZE);

Prevention

When it happens

Trigger: Passing a domain name containing a character whose numeric value is >= _keyMap.Length to a DomainTree-derived tree operation.

Common situations: Non-ASCII / Unicode hostnames not converted to Punycode (IDNA) before being passed to the tree; a stray emoji or accented character in a record owner name; binary garbage in a name.

Understand the failure class

Related errors


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

Appendix: source

Thrown at DnsServerCore/Dns/Trees/DomainTree.cs:166

                    if (throwException)
                        throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: label length cannot exceed 63 bytes.");

                    return null;
                }

                if ((labelLength == 1) && (domain[labelStart + 1] == '*')) //[*]
                {
                    key[keyOffset++] = 1;
                }
                else
                {
                    for (i = labelStart + 1; i <= labelEnd; i++)
                    {
                        labelChar = domain[i];
                        if (labelChar >= _keyMap.Length)
                        {
                            if (throwException)
                                throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: invalid character [" + labelChar + "] was found.");

                            return null;
                        }

                        labelKeyCode = _keyMap[labelChar];
                        if (labelKeyCode == 0xff)
                        {
                            if (throwException)
                                throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: invalid character [" + labelChar + "] was found.");

                            return null;
                        }

                        key[keyOffset++] = labelKeyCode;
                    }
                }

                key[keyOffset++] = 0; //[.]

View on GitHub (pinned to d0484b6c1e)