{"record":{"id":"ddcc1b175644f051","repo":"nopSolutions/nopCommerce","slug":"the-system-name-of-system-customer-roles-can-t-be","errorCode":null,"errorMessage":"The system name of system customer roles can't be edited.","messagePattern":"The system name of system customer roles can't be edited\\.","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"warning","filePath":"src/Presentation/Nop.Web/Areas/Admin/Controllers/CustomerRoleController.cs","lineNumber":151,"sourceCode":"    [HttpPost, ParameterBasedOnFormName(\"save-continue\", \"continueEditing\")]\n    [CheckPermission(StandardPermission.Customers.CUSTOMER_ROLES_CREATE_EDIT_DELETE)]\n    [CheckPermission(StandardPermission.Configuration.MANAGE_ACL)]\n    public virtual async Task<IActionResult> Edit(CustomerRoleModel model, bool continueEditing)\n    {\n        //try to get a customer role with the specified id\n        var customerRole = await _customerService.GetCustomerRoleByIdAsync(model.Id);\n        if (customerRole == null)\n            return RedirectToAction(\"List\");\n\n        try\n        {\n            if (ModelState.IsValid)\n            {\n                if (customerRole.IsSystemRole && !model.Active)\n                    throw new NopException(await _localizationService.GetResourceAsync(\"Admin.Customers.CustomerRoles.Fields.Active.CantEditSystem\"));\n\n                if (customerRole.IsSystemRole && !customerRole.SystemName.Equals(model.SystemName, StringComparison.InvariantCultureIgnoreCase))\n                    throw new NopException(await _localizationService.GetResourceAsync(\"Admin.Customers.CustomerRoles.Fields.SystemName.CantEditSystem\"));\n\n                if (NopCustomerDefaults.RegisteredRoleName.Equals(customerRole.SystemName, StringComparison.InvariantCultureIgnoreCase) &&\n                    model.PurchasedWithProductId > 0)\n                    throw new NopException(await _localizationService.GetResourceAsync(\"Admin.Customers.CustomerRoles.Fields.PurchasedWithProduct.Registered\"));\n\n                customerRole = model.ToEntity(customerRole);\n                await _customerService.UpdateCustomerRoleAsync(customerRole);\n\n                //activity log\n                await _customerActivityService.InsertActivityAsync(\"EditCustomerRole\",\n                    string.Format(await _localizationService.GetResourceAsync(\"ActivityLog.EditCustomerRole\"), customerRole.Name), customerRole);\n\n                _notificationService.SuccessNotification(await _localizationService.GetResourceAsync(\"Admin.Customers.CustomerRoles.Updated\"));\n\n                return continueEditing ? RedirectToAction(\"Edit\", new { id = customerRole.Id }) : RedirectToAction(\"List\");\n            }\n\n            //prepare model","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web/Areas/Admin/Controllers/CustomerRoleController.cs#L133-L169","documentation":"Thrown in the CustomerRole Edit action when a system role's SystemName is being changed (a case-insensitive comparison between the persisted SystemName and the posted model.SystemName fails). System names are programmatic identifiers referenced throughout nopCommerce code via constants (e.g. NopCustomerDefaults.RegisteredRoleName), so renaming them would break role resolution. It is a NopException shown as an error notification.","triggerScenarios":"POST to CustomerRole/Edit where the role is a system role and the model.SystemName differs (case-insensitively) from the existing customerRole.SystemName.","commonSituations":"An admin edits the 'System name' text box for a built-in role; a config import/seed overrides SystemName for a system role; localization confusion leads someone to 'translate' the system name.","solutions":["Do not modify the SystemName field for any role flagged IsSystemRole — it is read-only by contract.","If a different identifier is needed, create a new non-system role.","Check import/migration scripts to ensure they never overwrite SystemName on system roles.","Verify the posted model.SystemName exactly matches the stored value for system roles."],"exampleFix":"// before — model.SystemName edited for a system role -> NopException\n\n// after — render SystemName read-only in the view for system roles\n@if (Model.IsSystemRole)\n{\n    @Html.DisplayFor(model => model.SystemName)\n}\nelse\n{\n    @Html.EditorFor(model => model.SystemName)\n}","handlingStrategy":"validation","validationCode":"// Before saving: reject SystemName change for system roles\nvar role = await _customerService.GetCustomerRoleByIdAsync(model.Id);\nif (role?.IsSystemRole == true && !role.SystemName.Equals(model.SystemName, StringComparison.OrdinalIgnoreCase))\n{\n    ModelState.AddModelError(\"SystemName\", \"System role system names cannot be changed.\");\n    return View(model);\n}","typeGuard":"bool CanEditSystemName(CustomerRole role) => !role?.IsSystemRole ?? false;","tryCatchPattern":"// Existing try/catch renders the localized error notification; keep input consistent to avoid it.","preventionTips":["Make the SystemName field read-only for system roles in the UI.","Never overwrite SystemName in migration/seed scripts for built-in roles.","Treat SystemName as a programmatic constant, not a display label."],"tags":["nopcommerce","admin","customer-roles","business-rule","system-role","immutable","systemname"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}