TechnitiumSoftware/DnsServer · error · ArgumentOutOfRangeException

Resource record comment text cannot exceed 255 characters.

Error message

Resource record comment text cannot exceed 255 characters.

What it means

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.

Source

Thrown at DnsServerCore/Dns/ResourceRecords/GenericRecordInfo.cs:135

        }

        #endregion

        #region properties

        public virtual bool Disabled
        {
            get { return _disabled; }
            set { _disabled = value; }
        }

        public string Comments
        {
            get { return _comments; }
            set
            {
                if ((value is not null) && (value.Length > 255))
                    throw new ArgumentOutOfRangeException(nameof(Comments), "Resource record comment text cannot exceed 255 characters.");

                _comments = value;
            }
        }

        public DateTime LastModified
        {
            get { return _lastModified; }
            set { _lastModified = value; }
        }

        public virtual uint ExpiryTtl
        {
            get { return _expiryTtl; }
            set { _expiryTtl = value; }
        }

        public DateTime LastUsedOn

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Truncate the comment to 255 characters before assigning (consider storing longer text elsewhere).
  2. Validate comment length in your UI/API layer and reject or truncate with a user-facing message.
  3. If you need longer annotations, store them out-of-band (e.g. a separate notes store) rather than in the record comment.

Example fix

// before
record.Comments = longDescription; // 600 chars

// after
const int MAX_COMMENT = 255;
record.Comments = longDescription is null || longDescription.Length <= MAX_COMMENT
    ? longDescription
    : longDescription.Substring(0, MAX_COMMENT);
Defensive patterns

Strategy: validation

Validate before calling

const int MAX_RECORD_COMMENT = 255;
string safe = string.IsNullOrEmpty(comment) || comment.Length <= MAX_RECORD_COMMENT
    ? comment
    : comment.Substring(0, MAX_RECORD_COMMENT);
record.Comments = safe;

Type guard

static bool IsValidComment(string s) => s is null || s.Length <= 255;

Try / catch

try { record.Comments = comment; }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == nameof(record.Comments))
{ record.Comments = comment.Substring(0, 255); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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