OrchardCMS/OrchardCore · error · ArgumentException
The name cannot be null or empty.
Error message
The name cannot be null or empty.
What it means
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.
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.
Example fix
// before
await store.SetTokenAsync(user, provider, name, value, ct); // name may be ""
// after
if (!string.IsNullOrEmpty(name)) { await store.SetTokenAsync(user, provider, name, value, ct); } Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(loginProvider) || string.IsNullOrEmpty(name)) throw new ArgumentException("provider and name are required"); Type guard
bool IsValidTokenKey(string provider, string name) => !string.IsNullOrEmpty(provider) && !string.IsNullOrEmpty(name);
Try / catch
try { await store.SetTokenAsync(user, provider, name, value, ct); }
catch (ArgumentException ex) { _logger.LogError(ex, "Invalid token arguments"); throw; } Prevention
- 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
When it happens
Trigger: Calling SetTokenAsync directly with an empty name; ReplaceCodesAsync or SetAuthenticatorKeyAsync invoked by UserManager with misconfigured token provider settings producing empty names.
Common situations: Custom two-factor token providers passing empty constants; reflection-based or dynamic code building token keys from missing configuration; wrong UserManager token provider registration.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- The value cannot be null or empty.
- code cannot be null or empty.
- Incorrect value type assigned to a tag.
- Couldn't generate a unique user id. Too many attempts.
- Role does not exist.
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/a74d3eb39598d419.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs:673
{
u.UserTokens.Remove(userToken);
}
return Task.CompletedTask;
}
public Task SetTokenAsync(IUser user, string loginProvider, string name, string value, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(user);
if (string.IsNullOrEmpty(loginProvider))
{
throw new ArgumentException("The login provider cannot be null or empty.", nameof(loginProvider));
}
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException("The name cannot be null or empty.", nameof(name));
}
if (string.IsNullOrEmpty(value))
{
throw new ArgumentException("The value cannot be null or empty.", nameof(value));
}
var userToken = GetUserToken(user, loginProvider, name);
if (userToken == null && user is User u)
{
userToken = new UserToken
{
LoginProvider = loginProvider,
Name = name,
};
u.UserTokens.Add(userToken);View on GitHub (pinned to 4306c0717f)