{"record":{"id":"5f1b7123cf2f793f","repo":"TechnitiumSoftware/DnsServer","slug":"resource-record-comment-text-cannot-exceed-255-cha","errorCode":null,"errorMessage":"Resource record comment text cannot exceed 255 characters.","messagePattern":"Resource record comment text cannot exceed 255 characters\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/ResourceRecords/GenericRecordInfo.cs","lineNumber":135,"sourceCode":"        }\n\n        #endregion\n\n        #region properties\n\n        public virtual bool Disabled\n        {\n            get { return _disabled; }\n            set { _disabled = value; }\n        }\n\n        public string Comments\n        {\n            get { return _comments; }\n            set\n            {\n                if ((value is not null) && (value.Length > 255))\n                    throw new ArgumentOutOfRangeException(nameof(Comments), \"Resource record comment text cannot exceed 255 characters.\");\n\n                _comments = value;\n            }\n        }\n\n        public DateTime LastModified\n        {\n            get { return _lastModified; }\n            set { _lastModified = value; }\n        }\n\n        public virtual uint ExpiryTtl\n        {\n            get { return _expiryTtl; }\n            set { _expiryTtl = value; }\n        }\n\n        public DateTime LastUsedOn","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/ResourceRecords/GenericRecordInfo.cs#L117-L153","documentation":"Thrown by GenericRecordInfo.Comments setter when the supplied string is non-null and longer than 255 characters. The 255 limit is mandated by the binary persistence format: comments are stored via WriteShortString (a length-prefixed byte field), so anything longer would overflow the field and corrupt the record on disk. The check runs on every assignment to keep the invariant at the boundary.","triggerScenarios":"Assigning record.Comments to a string whose .Length > 255. Reachable from the web console record editor, the HTTP API, or any App/plugin that sets record metadata.","commonSituations":"Pasting a long note into a record's comment field; an automated provisioning script copying an unbounded description into Comments; bulk-import with a description column longer than 255 chars.","solutions":["Truncate the comment to 255 characters before assigning (consider storing longer text elsewhere).","Validate comment length in your UI/API layer and reject or truncate with a user-facing message.","If you need longer annotations, store them out-of-band (e.g. a separate notes store) rather than in the record comment."],"exampleFix":"// before\nrecord.Comments = longDescription; // 600 chars\n\n// after\nconst int MAX_COMMENT = 255;\nrecord.Comments = longDescription is null || longDescription.Length <= MAX_COMMENT\n    ? longDescription\n    : longDescription.Substring(0, MAX_COMMENT);","handlingStrategy":"validation","validationCode":"const int MAX_RECORD_COMMENT = 255;\nstring safe = string.IsNullOrEmpty(comment) || comment.Length <= MAX_RECORD_COMMENT\n    ? comment\n    : comment.Substring(0, MAX_RECORD_COMMENT);\nrecord.Comments = safe;","typeGuard":"static bool IsValidComment(string s) => s is null || s.Length <= 255;","tryCatchPattern":"try { record.Comments = comment; }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == nameof(record.Comments))\n{ record.Comments = comment.Substring(0, 255); }","preventionTips":["Enforce a 255-char limit in the record editor UI and API input validation.","Truncate long descriptions before assigning to Comments; store longer text elsewhere."],"tags":["validation","generic-record","comments","argument-range","serialization"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}