TechnitiumSoftware/DnsServer · error · DnsWebServiceException
User already exists: {username}
Error message
User already exists: {username} What it means
Thrown as DnsWebServiceException from CreateUser when _users.TryAdd(username, user) returns false, meaning a user with that username already exists. Usernames are lowercased before storage, so the uniqueness check is effectively case-insensitive. Returned over the API as HTTP 200 with status 'error'.
Source
Thrown at DnsServerCore/Auth/AuthManager.cs:941
throw new DnsWebServiceException("Cannot create more than 255 users.");
username = username.ToLowerInvariant();
User user = User.CreateLocalUser(displayName, username, password, iterations);
if (_users.TryAdd(username, user))
{
if (_users.Count > byte.MaxValue)
{
_users.TryRemove(username, out _); //undo
throw new DnsWebServiceException("Cannot create more than 255 users.");
}
user.AddToGroup(GetGroup(Group.EVERYONE));
return user;
}
throw new DnsWebServiceException("User already exists: " + username);
}
public User CreateSsoUser(string displayName, string username, string ssoIdentifier)
{
if (_users.Count >= byte.MaxValue)
throw new DnsWebServiceException("Cannot create more than 255 users.");
username = username.ToLowerInvariant();
User user = User.CreateSsoUser(displayName, username, ssoIdentifier);
if (_users.TryAdd(username, user))
{
if (_users.Count > byte.MaxValue)
{
_users.TryRemove(username, out _); //undo
throw new DnsWebServiceException("Cannot create more than 255 users.");
}View on GitHub (pinned to d0484b6c1e)
Solutions
- Check whether the username exists (case-insensitively) before creating, and skip or update instead.
- Pick a unique username.
- Delete the existing user first if a replacement is intended.
Example fix
// before
_dnsWebService._authManager.CreateUser(name, username, password);
// after
if (GetUser(username) is null)
_dnsWebService._authManager.CreateUser(name, username, password); Defensive patterns
Strategy: validation
Validate before calling
if (await GetUserAsync(username) is not null)
throw new InvalidOperationException($"User '{username}' already exists."); Try / catch
try { await client.CreateUserAsync(name, username, password); }
catch (HttpApiClientException ex) when (ex.Message.StartsWith("User already exists"))
{
// skip or update instead
} Prevention
- Check existence case-insensitively before creating.
- Make provisioning scripts idempotent.
When it happens
Trigger: Calling CreateUser with a username (lowercased) that is already a key in _users; e.g., creating 'Admin' when 'admin' exists.
Common situations: Re-running a provisioning script; an admin/User already created the same name; case-only differences (the code stores lowercased keys).
Related errors
- User already exists: {newUsername}
- User account is disabled. Please contact your administrator.
- Cannot create more than 255 users.
- Group already exists: {name}
- Group already exists: {newGroupName}
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/edd15803a2efab82.
Report an issue: GitHub.