nopSolutions/nopCommerce · error · NopException
Usernames are disabled
Error message
Usernames are disabled
What it means
Thrown by SetUsernameAsync as a NopException when _customerSettings.UsernamesEnabled is false. Username functionality is opt-in via the CustomerSettings.UsernamesEnabled flag; calling SetUsernameAsync while it's disabled is a configuration/caller mismatch.
Source
Thrown at src/Libraries/Nop.Services/Customers/CustomerRegistrationService.cs:568
subscription.Active = false;
await _newsLetterSubscriptionService.UpdateNewsLetterSubscriptionAsync(subscription);
}
}
}
/// <summary>
/// Sets a customer username
/// </summary>
/// <param name="customer">Customer</param>
/// <param name="newUsername">New Username</param>
/// <returns>A task that represents the asynchronous operation</returns>
public virtual async Task SetUsernameAsync(Customer customer, string newUsername)
{
ArgumentNullException.ThrowIfNull(customer);
if (!_customerSettings.UsernamesEnabled)
throw new NopException("Usernames are disabled");
newUsername = newUsername.Trim();
if (newUsername.Length > NopCustomerServicesDefaults.CustomerUsernameLength)
throw new NopException(await _localizationService.GetResourceAsync("Account.EmailUsernameErrors.UsernameTooLong"));
var user2 = await _customerService.GetCustomerByUsernameAsync(newUsername);
if (user2 != null && customer.Id != user2.Id)
throw new NopException(await _localizationService.GetResourceAsync("Account.EmailUsernameErrors.UsernameAlreadyExists"));
customer.Username = newUsername;
await _customerService.UpdateCustomerAsync(customer);
}
#endregion
}View on GitHub (pinned to 64bdf2ff08)
Solutions
- Enable usernames in Admin > Configuration > Settings > Customer settings (UsernamesEnabled = true), or set the setting via code.
- Guard the caller: only expose/invoke SetUsernameAsync when _customerSettings.UsernamesEnabled is true.
- If usernames must stay off, remove the username-change UI path entirely.
Example fix
// before
await _customerRegistrationService.SetUsernameAsync(customer, newUsername);
// after
if (!_customerSettings.UsernamesEnabled)
return; // or notify user that usernames are disabled
await _customerRegistrationService.SetUsernameAsync(customer, newUsername); Defensive patterns
Strategy: type-guard
Validate before calling
if (!_customerSettings.UsernamesEnabled) return; // usernames feature off await _customerRegistrationService.SetUsernameAsync(customer, newUsername);
Type guard
static bool UsernamesAreOn(ICustomerSettings s) => s.UsernamesEnabled;
Try / catch
try { await _customerRegistrationService.SetUsernameAsync(customer, username); }
catch (NopException ex) when (ex.Message == "Usernames are disabled")
{ /* hide the username UI path */ } Prevention
- Gate the 'change username' UI behind _customerSettings.UsernamesEnabled.
- Enable the setting in Admin > Customer settings before exposing username features.
- Document that SetUsernameAsync requires the setting to be on.
When it happens
Trigger: Invoking SetUsernameAsync (directly or via a 'change username' admin/customer action) when CustomerSettings > UsernamesEnabled is unchecked in admin or set to false in settings.
Common situations: A plugin or custom flow assumes usernames are on; an admin toggled UsernamesEnabled off after the feature shipped; default install (usernames often disabled by default).
Related errors
- Account.EmailUsernameErrors.UsernameTooLong
- Account.EmailUsernameErrors.UsernameAlreadyExists
- Primary exchange rate currency is not set
- Primary exchange rate currency cannot be loaded
- Email account could not be loaded
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/76f7b2eaffbd8656.
Report an issue: GitHub.