{"record":{"id":"a51818560dd4ad36","repo":"nopSolutions/nopCommerce","slug":"registered-role-could-not-be-loaded","errorCode":null,"errorMessage":"'Registered' role could not be loaded","messagePattern":"'Registered' role could not be loaded","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"critical","filePath":"src/Libraries/Nop.Services/Customers/CustomerRegistrationService.cs","lineNumber":331,"sourceCode":"            case PasswordFormat.Clear:\r\n                customerPassword.Password = request.Password;\r\n                break;\r\n            case PasswordFormat.Encrypted:\r\n                customerPassword.Password = _encryptionService.EncryptText(request.Password);\r\n                break;\r\n            case PasswordFormat.Hashed:\r\n                var saltKey = _encryptionService.CreateSaltKey(NopCustomerServicesDefaults.PasswordSaltKeySize);\r\n                customerPassword.PasswordSalt = saltKey;\r\n                customerPassword.Password = _encryptionService.CreatePasswordHash(request.Password, saltKey, _customerSettings.HashedPasswordFormat);\r\n                break;\r\n        }\r\n\r\n        await _customerService.InsertCustomerPasswordAsync(customerPassword);\r\n\r\n        request.Customer.Active = request.IsApproved;\r\n\r\n        //add to 'Registered' role\r\n        var registeredRole = await _customerService.GetCustomerRoleBySystemNameAsync(NopCustomerDefaults.RegisteredRoleName) ?? throw new NopException(\"'Registered' role could not be loaded\");\r\n\r\n        await _customerService.AddCustomerRoleMappingAsync(new CustomerCustomerRoleMapping { CustomerId = request.Customer.Id, CustomerRoleId = registeredRole.Id });\r\n\r\n        //remove from 'Guests' role            \r\n        if (await _customerService.IsGuestAsync(request.Customer))\r\n        {\r\n            var guestRole = await _customerService.GetCustomerRoleBySystemNameAsync(NopCustomerDefaults.GuestsRoleName);\r\n            await _customerService.RemoveCustomerRoleMappingAsync(request.Customer, guestRole);\r\n        }\r\n\r\n        //add reward points for customer registration (if enabled)\r\n        if (_rewardPointsSettings.Enabled && _rewardPointsSettings.PointsForRegistration > 0)\r\n        {\r\n            var endDate = _rewardPointsSettings.RegistrationPointsValidity > 0\r\n                ? (DateTime?)DateTime.UtcNow.AddDays(_rewardPointsSettings.RegistrationPointsValidity.Value) : null;\r\n            await _rewardPointService.AddRewardPointsHistoryEntryAsync(request.Customer, _rewardPointsSettings.PointsForRegistration,\r\n                request.StoreId, await _localizationService.GetResourceAsync(\"RewardPoints.Message.EarnedForRegistration\"), endDate: endDate);\r\n        }\r","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/Customers/CustomerRegistrationService.cs#L313-L349","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait _customerRegistrationService.RegisterCustomerAsync(request);\n\n// after\nvar registeredRole = await _customerService\n    .GetCustomerRoleBySystemNameAsync(NopCustomerDefaults.RegisteredRoleName);\nif (registeredRole is null)\n    throw new InvalidOperationException(\n        \"Seed data missing: 'Registered' role not found. Re-run role seeding.\");\nawait _customerRegistrationService.RegisterCustomerAsync(request);","handlingStrategy":"validation","validationCode":"var role = await _customerService\n    .GetCustomerRoleBySystemNameAsync(NopCustomerDefaults.RegisteredRoleName);\nif (role is null)\n    throw new InvalidOperationException(\n        \"Seed data missing: 'Registered' role not found. Re-run role seeding.\");","typeGuard":null,"tryCatchPattern":"try { await _customerRegistrationService.RegisterCustomerAsync(request); }\ncatch (NopException ex) when (ex.Message.Contains(\"'Registered' role\"))\n{ /* surface a 'system misconfiguration' page, alert ops to re-seed roles */ }","preventionTips":["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."],"tags":["customer","registration","role","seeding","data-integrity"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}