{"record":{"id":"a910ad72462be742","repo":"TechnitiumSoftware/DnsServer","slug":"block-list-url-or-comment-line-length-cannot-exc","errorCode":null,"errorMessage":"Block list URL (or comment line) length cannot exceed 255 characters.","messagePattern":"Block list URL \\(or comment line\\) length cannot exceed 255 characters\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/ZoneManagers/BlockListZoneManager.cs","lineNumber":1046,"sourceCode":"            set\n            {\n                if (value is null)\n                {\n                    value = [];\n                }\n                else if (value.Count > 255)\n                {\n                    throw new ArgumentException(\"Cannot configure more than 255 block list URLs.\", nameof(BlockListUrls));\n                }\n                else\n                {\n                    List<string> uniqueList = new List<string>(value.Count);\n                    int commentCount = 0;\n\n                    foreach (string url in value)\n                    {\n                        if (url.Length > 255)\n                            throw new ArgumentException(\"Block list URL (or comment line) length cannot exceed 255 characters.\", nameof(BlockListUrls));\n\n                        if (url.TrimStart().StartsWith('#'))\n                        {\n                            uniqueList.Add(url);\n                            commentCount++;\n                            continue;\n                        }\n\n                        //do URL validation\n                        try\n                        {\n                            if (url.StartsWith('!'))\n                                _ = new Uri(url.Substring(1));\n                            else\n                                _ = new Uri(url);\n                        }\n                        catch (Exception ex)\n                        {","sourceCodeStart":1028,"sourceCodeEnd":1064,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/ZoneManagers/BlockListZoneManager.cs#L1028-L1064","documentation":"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.","triggerScenarios":"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.","commonSituations":"Subscription URLs carrying API keys/parameters; malformed entries where a whole line was pasted instead of one URL.","solutions":["Shorten the offending URL (use a redirect/shortener or trim unnecessary query parameters) to <= 255 chars.","Split an over-long comment line into multiple shorter comment lines.","Validate each entry's length before assigning the collection."],"exampleFix":"// before\nblockListZoneManager.BlockListUrls = new[] { veryLongUrl }; // Length > 255 -> throws\n// after\nblockListZoneManager.BlockListUrls = new[] { ShortenOrTrim(veryLongUrl) }; // Length <= 255","handlingStrategy":"validation","validationCode":"foreach (var url in urls ?? Array.Empty<string>())\n    if (url.Length > 255)\n        throw new InvalidOperationException($\"Entry exceeds 255 chars: {url.Substring(0, 40)}...\");\nblockListZoneManager.BlockListUrls = urls;","typeGuard":"static bool AllBlockListEntriesFit(IEnumerable<string> urls) => urls.All(u => u.Length <= 255);","tryCatchPattern":"try { blockListZoneManager.BlockListUrls = urls; }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"cannot exceed 255 characters\"))\n{ blockListZoneManager.BlockListUrls = urls.Select(TrimOrShorten).ToList(); }","preventionTips":["Reject over-long entries at the input layer, before they reach the setter.","Use short subscription URLs; strip unnecessary query parameters.","Split long comment lines into several shorter lines.","Unit-test your config builder against the 255-char per-entry limit."],"tags":["dns","blocklist","validation","configuration"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}