{"record":{"id":"a74d3eb39598d419","repo":"OrchardCMS/OrchardCore","slug":"the-name-cannot-be-null-or-empty","errorCode":null,"errorMessage":"The name cannot be null or empty.","messagePattern":"The name cannot be null or empty\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs","lineNumber":673,"sourceCode":"        {\n            u.UserTokens.Remove(userToken);\n        }\n\n        return Task.CompletedTask;\n    }\n\n    public Task SetTokenAsync(IUser user, string loginProvider, string name, string value, CancellationToken cancellationToken = default)\n    {\n        ArgumentNullException.ThrowIfNull(user);\n\n        if (string.IsNullOrEmpty(loginProvider))\n        {\n            throw new ArgumentException(\"The login provider cannot be null or empty.\", nameof(loginProvider));\n        }\n\n        if (string.IsNullOrEmpty(name))\n        {\n            throw new ArgumentException(\"The name cannot be null or empty.\", nameof(name));\n        }\n\n        if (string.IsNullOrEmpty(value))\n        {\n            throw new ArgumentException(\"The value cannot be null or empty.\", nameof(value));\n        }\n\n        var userToken = GetUserToken(user, loginProvider, name);\n\n        if (userToken == null && user is User u)\n        {\n            userToken = new UserToken\n            {\n                LoginProvider = loginProvider,\n                Name = name,\n            };\n\n            u.UserTokens.Add(userToken);","sourceCodeStart":655,"sourceCodeEnd":691,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs#L655-L691","documentation":"Thrown by UserStore.SetTokenAsync when the token 'name' is null or empty. This method stores two-factor and authenticator tokens per provider, and both the provider and token name are required keys, so blank names are rejected with ArgumentException before any storage happens.","triggerScenarios":"Calling SetTokenAsync directly with an empty name; ReplaceCodesAsync or SetAuthenticatorKeyAsync invoked by UserManager with misconfigured token provider settings producing empty names.","commonSituations":"Custom two-factor token providers passing empty constants; reflection-based or dynamic code building token keys from missing configuration; wrong UserManager token provider registration.","solutions":["Ensure the token name argument is a non-empty constant (e.g. 'AuthenticatorKey').","Check custom IUserTwoFactorTokenProvider implementations for empty name values.","Validate inputs before calling the store and throw a descriptive error upstream.","Catch ArgumentException to report a configuration bug instead of crashing the request."],"exampleFix":"// before\nawait store.SetTokenAsync(user, provider, name, value, ct); // name may be \"\"\n// after\nif (!string.IsNullOrEmpty(name)) { await store.SetTokenAsync(user, provider, name, value, ct); }","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(loginProvider) || string.IsNullOrEmpty(name)) throw new ArgumentException(\"provider and name are required\");","typeGuard":"bool IsValidTokenKey(string provider, string name) => !string.IsNullOrEmpty(provider) && !string.IsNullOrEmpty(name);","tryCatchPattern":"try { await store.SetTokenAsync(user, provider, name, value, ct); }\ncatch (ArgumentException ex) { _logger.LogError(ex, \"Invalid token arguments\"); throw; }","preventionTips":["Use named constants for token names (e.g. 'AuthenticatorKey')","Validate configuration that feeds token keys","Never build token names dynamically from optional config","Write tests covering two-factor setup flows"],"tags":["users","two-factor","arguments"],"backgroundTag":"empty-required-field","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}