TechnitiumSoftware/DnsServer · error · ArgumentException

Block list URL (or comment line) length cannot exceed 255 ch

Error message

Block list URL (or comment line) length cannot exceed 255 characters.

What it means

Thrown by the BlockListUrls setter while iterating each entry: any single URL (or comment line) whose Length exceeds 255 characters is rejected. Each entry is stored via WriteShortString (a length-prefixed byte string), hence the per-entry 255-char limit. Comment lines (starting with '#') are also subject to this limit.

Source

Thrown at DnsServerCore/Dns/ZoneManagers/BlockListZoneManager.cs:1046

            set
            {
                if (value is null)
                {
                    value = [];
                }
                else if (value.Count > 255)
                {
                    throw new ArgumentException("Cannot configure more than 255 block list URLs.", nameof(BlockListUrls));
                }
                else
                {
                    List<string> uniqueList = new List<string>(value.Count);
                    int commentCount = 0;

                    foreach (string url in value)
                    {
                        if (url.Length > 255)
                            throw new ArgumentException("Block list URL (or comment line) length cannot exceed 255 characters.", nameof(BlockListUrls));

                        if (url.TrimStart().StartsWith('#'))
                        {
                            uniqueList.Add(url);
                            commentCount++;
                            continue;
                        }

                        //do URL validation
                        try
                        {
                            if (url.StartsWith('!'))
                                _ = new Uri(url.Substring(1));
                            else
                                _ = new Uri(url);
                        }
                        catch (Exception ex)
                        {

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Shorten the offending URL (use a redirect/shortener or trim unnecessary query parameters) to <= 255 chars.
  2. Split an over-long comment line into multiple shorter comment lines.
  3. Validate each entry's length before assigning the collection.

Example fix

// before
blockListZoneManager.BlockListUrls = new[] { veryLongUrl }; // Length > 255 -> throws
// after
blockListZoneManager.BlockListUrls = new[] { ShortenOrTrim(veryLongUrl) }; // Length <= 255
Defensive patterns

Strategy: validation

Validate before calling

foreach (var url in urls ?? Array.Empty<string>())
    if (url.Length > 255)
        throw new InvalidOperationException($"Entry exceeds 255 chars: {url.Substring(0, 40)}...");
blockListZoneManager.BlockListUrls = urls;

Type guard

static bool AllBlockListEntriesFit(IEnumerable<string> urls) => urls.All(u => u.Length <= 255);

Try / catch

try { blockListZoneManager.BlockListUrls = urls; }
catch (ArgumentException ex) when (ex.Message.Contains("cannot exceed 255 characters"))
{ blockListZoneManager.BlockListUrls = urls.Select(TrimOrShorten).ToList(); }

Prevention

When it happens

Trigger: A block list URL with long query strings or a comment line longer than 255 chars; pasting a URL that includes a long token/path.

Common situations: Subscription URLs carrying API keys/parameters; malformed entries where a whole line was pasted instead of one URL.

Related errors


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