OrchardCMS/OrchardCore · error · ArgumentException
The value cannot be null or empty.
Error message
The value cannot be null or empty.
What it means
Thrown by UserStore.SetTokenAsync when the token 'value' is null or empty. A token entry must carry a non-empty value since it is later retrieved verbatim by GetTokenAsync (e.g. recovery codes, authenticator keys).
Solutions
- Generate a valid value (e.g. KeyGeneration.GenerateRandomKey) before storing.
- Guard ReplaceCodesAsync so it never persists an empty code string.
- Catch ArgumentException and re-run the token generation step.
- Inspect the token provider that produced the empty value.
Example fix
// before
await _userManager.SetAuthenticationProviderKeyAsync(user, key); // key == ""
// after
if (string.IsNullOrEmpty(key)) { key = Convert.ToBase64String(KeyGeneration.GenerateRandomKey(20)); }
await _userManager.SetAuthenticationProviderKeyAsync(user, key); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(value)) throw new InvalidOperationException("Refusing to store an empty token value"); Type guard
bool CanStoreToken(string provider, string name, string value) => !string.IsNullOrEmpty(provider) && !string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value);
Try / catch
try { await store.SetTokenAsync(user, provider, name, value, ct); }
catch (ArgumentException ex) when (ex.ParamName == "value")
{ _logger.LogError(ex, "Empty token value for {Provider}/{Name}", provider, name); } Prevention
- Generate values with a vetted key generator before persisting
- Never persist empty code sets; regenerate instead
- Assert token generation success in two-factor enable flows
- Log and retry generation when output is empty
When it happens
Trigger: Calling SetTokenAsync with an empty value; ReplaceCodesAsync receiving an empty recovery-code set; SetAuthenticatorKeyAsync invoked when key generation returned an empty string.
Common situations: Custom key generators failing silently; recovery-code generation producing zero codes; two-factor setup flows where the key was never generated before persisting.
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 name 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/02bb7a0df3495828.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs:678
}
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);
}
// Encrypt the token.
if (userToken != null)
{View on GitHub (pinned to 4306c0717f)