nopSolutions/nopCommerce · critical · NopException
'Registered' role could not be loaded
Error message
'Registered' role could not be loaded
What it means
Thrown during customer registration (after a password is stored and the customer marked active) when GetCustomerRoleBySystemNameAsync for the 'Registered' system role returns null. The 'Registered' role is a seed/system role that must exist in the database; its absence means the store's role seeding is incomplete or corrupt.
Source
Thrown at src/Libraries/Nop.Services/Customers/CustomerRegistrationService.cs:331
case PasswordFormat.Clear:
customerPassword.Password = request.Password;
break;
case PasswordFormat.Encrypted:
customerPassword.Password = _encryptionService.EncryptText(request.Password);
break;
case PasswordFormat.Hashed:
var saltKey = _encryptionService.CreateSaltKey(NopCustomerServicesDefaults.PasswordSaltKeySize);
customerPassword.PasswordSalt = saltKey;
customerPassword.Password = _encryptionService.CreatePasswordHash(request.Password, saltKey, _customerSettings.HashedPasswordFormat);
break;
}
await _customerService.InsertCustomerPasswordAsync(customerPassword);
request.Customer.Active = request.IsApproved;
//add to 'Registered' role
var registeredRole = await _customerService.GetCustomerRoleBySystemNameAsync(NopCustomerDefaults.RegisteredRoleName) ?? throw new NopException("'Registered' role could not be loaded");
await _customerService.AddCustomerRoleMappingAsync(new CustomerCustomerRoleMapping { CustomerId = request.Customer.Id, CustomerRoleId = registeredRole.Id });
//remove from 'Guests' role
if (await _customerService.IsGuestAsync(request.Customer))
{
var guestRole = await _customerService.GetCustomerRoleBySystemNameAsync(NopCustomerDefaults.GuestsRoleName);
await _customerService.RemoveCustomerRoleMappingAsync(request.Customer, guestRole);
}
//add reward points for customer registration (if enabled)
if (_rewardPointsSettings.Enabled && _rewardPointsSettings.PointsForRegistration > 0)
{
var endDate = _rewardPointsSettings.RegistrationPointsValidity > 0
? (DateTime?)DateTime.UtcNow.AddDays(_rewardPointsSettings.RegistrationPointsValidity.Value) : null;
await _rewardPointService.AddRewardPointsHistoryEntryAsync(request.Customer, _rewardPointsSettings.PointsForRegistration,
request.StoreId, await _localizationService.GetResourceAsync("RewardPoints.Message.EarnedForRegistration"), endDate: endDate);
}
View on GitHub (pinned to 64bdf2ff08)
Solutions
- Re-seed the system customer roles: run the store installation/upgrade step that inserts built-in roles (Registered, Guests, Administrators, ForumModerators, Vendors) from NopCustomerDefaults.
- Manually insert the missing role row: SystemName='Registered', Name='Registered', Active=1, IsSystemRole=1.
- Verify no custom code or script deleted system roles; audit the CustomerRole table for IsSystemRole=1 rows.
- If the DB is from an older version, run the nopCommerce upgrade scripts which re-ensure seed roles.
Example fix
// before
await _customerRegistrationService.RegisterCustomerAsync(request);
// after
var registeredRole = await _customerService
.GetCustomerRoleBySystemNameAsync(NopCustomerDefaults.RegisteredRoleName);
if (registeredRole is null)
throw new InvalidOperationException(
"Seed data missing: 'Registered' role not found. Re-run role seeding.");
await _customerRegistrationService.RegisterCustomerAsync(request); Defensive patterns
Strategy: validation
Validate before calling
var role = await _customerService
.GetCustomerRoleBySystemNameAsync(NopCustomerDefaults.RegisteredRoleName);
if (role is null)
throw new InvalidOperationException(
"Seed data missing: 'Registered' role not found. Re-run role seeding."); Try / catch
try { await _customerRegistrationService.RegisterCustomerAsync(request); }
catch (NopException ex) when (ex.Message.Contains("'Registered' role"))
{ /* surface a 'system misconfiguration' page, alert ops to re-seed roles */ } Prevention
- Run the official install/upgrade routine on every environment so seed roles exist.
- Add a startup health check verifying system roles resolve.
- Protect CustomerRole rows where IsSystemRole=1 from deletion at the DB/app layer.
When it happens
Trigger: Any successful registration flow (Approve, user signup) reaching the line that assigns the Registered role, when the CustomerRole table lacks a row with SystemName == NopCustomerDefaults.RegisteredRoleName ("Registered"). Triggered inside CustomerRegistrationService registration approval.
Common situations: Database restored from a partial backup that dropped seed roles; a manual cleanup that deleted system roles; a migration that ran before role seeding; a custom DB initializer that skipped the standard sample-data/seed step.
Related errors
- System role could not be deleted
- Customer could not be loaded
- Shipping is required, but address is not available. Order ID
- Email cannot be null
- Account.EmailUsernameErrors.NewEmailIsNotValid
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/a51818560dd4ad36.
Report an issue: GitHub.