TechnitiumSoftware/DnsServer · error · FormatException

Invalid AdGuard Upstreams config file format: missing upstre

Error message

Invalid AdGuard Upstreams config file format: missing upstream servers.

What it means

Thrown while parsing an AdGuard Upstreams file when a domain-scoped line declares an explicit upstream server list after the ']' bracket but none could be parsed (the forwarderRecords list stayed empty after consuming the line). FormatException is raised.

Source

Thrown at Apps/AdvancedForwardingApp/App.cs:680

                                    string word = PopWord(ref forwarder);

                                    while (word.Length > 0)
                                    {
                                        string nextWord = PopWord(ref forwarder);

                                        if (nextWord.StartsWith('('))
                                        {
                                            word += " " + nextWord;
                                            nextWord = PopWord(ref forwarder);
                                        }

                                        forwarderRecords.Add(GetForwarderRecord(NameServerAddress.Parse(word), _dnssecValidation, _configProxyServer));

                                        word = nextWord;
                                    }

                                    if (forwarderRecords.Count == 0)
                                        throw new FormatException("Invalid AdGuard Upstreams config file format: missing upstream servers.");

                                    forwardings.Add(new Forwarding(forwarderRecords, domains));
                                }
                            }
                            else
                            {
                                defaultForwarderRecords.Add(GetForwarderRecord(NameServerAddress.Parse(line), _dnssecValidation, _configProxyServer));
                            }
                        }

                        _configFileLastModified = File.GetLastWriteTimeUtc(fS.SafeFileHandle);
                    }

                    _defaultForwarderRecords = defaultForwarderRecords;
                    _forwardings = forwardings;

                    _dnsServer.WriteLog("The app has successfully loaded AdGuard Upstreams config file: " + _configFile);
                }

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Add one or more valid upstream servers after the ']' on that line, e.g. '[/example.com/] tls://1.1.1.1'.
  2. Ensure each server token is a value NameServerAddress.Parse can accept (IP, DoH/DoT URL).
  3. If the domain should use the default upstream, use '#' instead of leaving it blank.

Example fix

// before (upstreams file)
[/example.com/]
// after
[/example.com/] https://dns.google/dns-query
Defensive patterns

Strategy: validation

Validate before calling

foreach (string line in File.ReadAllLines(upstreamsPath))
{
    string t = line.TrimStart();
    if (t.StartsWith('['))
    {
        int i = t.LastIndexOf(']');
        if (i >= 0 && t.Substring(i + 1).Trim() == string.Empty)
            throw new FormatException($"AdGuard upstreams line has no server after ']': {line}");
    }
}

Prevention

When it happens

Trigger: An AdGuard upstreams line like '[/example.com/]' with no server tokens after the bracket, or whose post-bracket text is only whitespace/parentheses, leaving zero upstream records.

Common situations: Trailing whitespace after ']' with no server; malformed parenthesis grouping consumed by PopWord but yielding no server; copy-paste that dropped the server name.

Related errors


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