TechnitiumSoftware/DnsServer · error · FormatException
Invalid AdGuard Upstreams config file format: missing defaul
Error message
Invalid AdGuard Upstreams config file format: missing default upstream servers.
What it means
Thrown while parsing an AdGuard Upstreams file when a domain-scoped line uses '#' as its upstream (the AdGuard convention meaning 'use the default upstream'), but no default upstream servers were defined earlier in the file. The defaultForwarderRecords list is empty, so FormatException is raised.
Source
Thrown at Apps/AdvancedForwardingApp/App.cs:655
if (line.Length == 0)
continue; //skip empty line
if (line.StartsWith('#'))
continue; //skip comment line
if (line.StartsWith('['))
{
int i = line.LastIndexOf(']');
if (i < 0)
throw new FormatException("Invalid AdGuard Upstreams config file format: missing ']' bracket.");
string[] domains = line.Substring(1, i - 1).Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
string forwarder = line.Substring(i + 1);
if (forwarder == "#")
{
if (defaultForwarderRecords.Count == 0)
throw new FormatException("Invalid AdGuard Upstreams config file format: missing default upstream servers.");
forwardings.Add(new Forwarding(defaultForwarderRecords, domains));
}
else
{
List<DnsForwarderRecordData> forwarderRecords = new List<DnsForwarderRecordData>();
string word = PopWord(ref forwarder);
while (word.Length > 0)
{
string nextWord = PopWord(ref forwarder);
if (nextWord.StartsWith('('))
{
word += " " + nextWord;
nextWord = PopWord(ref forwarder);
}
View on GitHub (pinned to d0484b6c1e)
Solutions
- Add at least one default upstream server line at the top of the AdGuard upstreams file before any '[/.../] #' line (e.g. 'https://dns.google/dns-query').
- Reorder so all default (non-bracketed) upstream lines come before domain-specific '#' rules.
- If you do not want a shared default, replace '#' with an explicit upstream server on that line.
Example fix
// before (upstreams file) [/example.com/] # // after https://dns.google/dns-query [/example.com/] #
Defensive patterns
Strategy: validation
Validate before calling
// Ensure at least one default (non-'[') upstream line precedes any '#'-default rule.
var lines = File.ReadAllLines(upstreamsPath).Where(l => { var t = l.TrimStart(); return t.Length > 0 && !t.StartsWith('#'); });
bool hasDefault = lines.Any(l => !l.TrimStart().StartsWith('['));
bool usesHashDefault = lines.Any(l => l.TrimStart().StartsWith('[') && l.Substring(l.LastIndexOf(']') + 1).Trim() == "#");
if (usesHashDefault && !hasDefault) throw new FormatException("AdGuard upstreams uses '#' default but defines no default upstream line."); Prevention
- Place default upstream server lines at the top of the AdGuard file.
- Avoid '#' default references until at least one default server is declared.
- Re-download upstream files from a verified source.
When it happens
Trigger: An AdGuard upstreams file where the first domain-specific line is '[/example.com/] #' (use default) but no plain upstream lines (the default servers) appeared before it. Default servers are the non-'[' lines at the top of the file.
Common situations: Deleting the top default-server lines of an AdGuard upstreams file while keeping '#' references; pasting only the domain-specific rules; file truncated at the top.
Related errors
- Invalid AdGuard Upstreams config file format: missing ']' br
- Invalid AdGuard Upstreams config file format: missing upstre
- Network group map contains an invalid network address: {netw
- Groups array was not defined.
- Forwarder was not defined: {forwarderName}
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/ef655391c719b8c9.
Report an issue: GitHub.