{"record":{"id":"31c459bbf209bd1c","repo":"TechnitiumSoftware/DnsServer","slug":"cannot-create-more-than-255-users","errorCode":null,"errorMessage":"Cannot create more than 255 users.","messagePattern":"Cannot create more than 255 users\\.","errorType":"exception","errorClass":"DnsWebServiceException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Auth/AuthManager.cs","lineNumber":923,"sourceCode":"\n            return null;\n        }\n\n        public User GetSsoUser(string ssoIdentifier)\n        {\n            foreach (KeyValuePair<string, User> user in _users)\n            {\n                if (ssoIdentifier.Equals(user.Value.SsoIdentifier, StringComparison.Ordinal) && user.Value.IsSsoUser)\n                    return user.Value;\n            }\n\n            return null;\n        }\n\n        public User CreateUser(string displayName, string username, string password, int iterations = User.DEFAULT_ITERATIONS)\n        {\n            if (_users.Count >= byte.MaxValue)\n                throw new DnsWebServiceException(\"Cannot create more than 255 users.\");\n\n            username = username.ToLowerInvariant();\n\n            User user = User.CreateLocalUser(displayName, username, password, iterations);\n\n            if (_users.TryAdd(username, user))\n            {\n                if (_users.Count > byte.MaxValue)\n                {\n                    _users.TryRemove(username, out _); //undo\n                    throw new DnsWebServiceException(\"Cannot create more than 255 users.\");\n                }\n\n                user.AddToGroup(GetGroup(Group.EVERYONE));\n                return user;\n            }\n\n            throw new DnsWebServiceException(\"User already exists: \" + username);","sourceCodeStart":905,"sourceCodeEnd":941,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Auth/AuthManager.cs#L905-L941","documentation":"Thrown as DnsWebServiceException from CreateUser when _users.Count is already >= 255 (byte.MaxValue) before attempting to add. The hard cap exists because user identifiers are stored as a byte. Returned over the API as HTTP 200 with status 'error'.","triggerScenarios":"Calling CreateUser (POST /api/users/create or similar) when the user dictionary already holds 255 users; the pre-add guard fails fast.","commonSituations":"Bulk-provisioning users from LDAP/SSO import or a script; long-running server that accumulated users up to the cap.","solutions":["Delete unused user accounts to free slots below 255 before creating new ones.","Consolidate access via groups/SSO rather than creating many local users.","Track _users.Count before calling create when bulk-provisioning."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (await GetUserCountAsync() >= 255)\n    throw new InvalidOperationException(\"User cap (255) reached; delete unused users first.\");","typeGuard":null,"tryCatchPattern":"try { await client.CreateUserAsync(name, username, password); }\ncatch (HttpApiClientException ex) when (ex.Message.Contains(\"Cannot create more than 255 users\"))\n{\n    await FreeUpUserSlotsAsync();\n}","preventionTips":["Monitor user count when bulk-provisioning.","Prefer SSO/groups over many local accounts."],"tags":["auth","user-management","limits"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}