TechnitiumSoftware/DnsServer · error · ArgumentException
Display name length cannot exceed 255 characters.
Error message
Display name length cannot exceed 255 characters.
What it means
Thrown by the User.DisplayName setter when the supplied value exceeds 255 characters. The limit is enforced because the display name is persisted via WriteShortString, which encodes length in a bounded prefix; a longer string would corrupt the saved user record. ArgumentException is used (not InvalidOperationException) because the argument itself is invalid. A null/whitespace value is allowed and falls back to the username.
Source
Thrown at DnsServerCore/Auth/User.cs:448
public int CompareTo(User other)
{
return _username.CompareTo(other._username);
}
#endregion
#region properties
public string DisplayName
{
get { return _displayName; }
set
{
if (string.IsNullOrWhiteSpace(value))
_displayName = _username;
else if (value.Length > 255)
throw new ArgumentException("Display name length cannot exceed 255 characters.", nameof(DisplayName));
else
_displayName = value;
}
}
public string Username
{ get { return _username; } }
public bool IsSsoUser
{ get { return _isSsoUser; } }
public string SsoIdentifier
{ get { return _ssoIdentifier; } }
public UserPasswordHashType PasswordHashType
{ get { return _passwordHashType; } }
public string PasswordHashView on GitHub (pinned to d0484b6c1e)
Solutions
- Truncate the input to 255 characters before assigning, or reject it at the form/API layer.
- Sanitize mapped SSO/LDAP attributes (substring 0..255) during provisioning.
- Add client-side maxlength=255 on the display-name input.
Example fix
// before user.DisplayName = displayName; // after user.DisplayName = displayName?.Length > 255 ? displayName.Substring(0, 255) : displayName;
Defensive patterns
Strategy: validation
Validate before calling
const int MAX = 255;
if (!string.IsNullOrWhiteSpace(value) && value.Length > MAX)
value = value.Substring(0, MAX);
user.DisplayName = value; Type guard
static bool IsValidDisplayName(string value) => string.IsNullOrWhiteSpace(value) || value.Length <= 255;
Prevention
- Enforce maxlength=255 on the display-name input client-side.
- Truncate mapped SSO/LDAP attributes during provisioning.
- Validate length in the API handler and return 400 early.
When it happens
Trigger: Assigning user.DisplayName = someLongString where someLongString.Length > 255, typically from an admin profile-edit form or an LDAP/SSO attribute mapping that pulls an unbounded display name.
Common situations: SSO/LDAP 'displayName' or 'CN' attribute mapped without truncation; copy-paste of a long descriptive string; a sync job that writes raw directory data into DisplayName.
Related errors
- Token name length cannot exceed 255 characters.
- Group name length cannot exceed 255 characters.
- Username length cannot exceed 255 characters.
- Invalid time-based one-time password (TOTP) was attempted fo
- Cannot add user to group: user can be member of max 255 grou
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/b503817a09f4dedc.
Report an issue: GitHub.