{"record":{"id":"3a62ab27f6abc859","repo":"nopSolutions/nopCommerce","slug":"system-customer-account-customer-systemname-co","errorCode":null,"errorMessage":"System customer account ({customer.SystemName}) could not be deleted","messagePattern":"System customer account \\((.+?)\\) could not be deleted","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/Customers/CustomerService.cs","lineNumber":342,"sourceCode":"    /// </returns>\r\n    public virtual async Task<Customer> GetShoppingCartCustomerAsync(IList<ShoppingCartItem> shoppingCart)\r\n    {\r\n        var customerId = shoppingCart.FirstOrDefault()?.CustomerId;\r\n\r\n        return customerId.HasValue && customerId != 0 ? await GetCustomerByIdAsync(customerId.Value) : null;\r\n    }\r\n\r\n    /// <summary>\r\n    /// Delete a customer\r\n    /// </summary>\r\n    /// <param name=\"customer\">Customer</param>\r\n    /// <returns>A task that represents the asynchronous operation</returns>\r\n    public virtual async Task DeleteCustomerAsync(Customer customer)\r\n    {\r\n        ArgumentNullException.ThrowIfNull(customer);\r\n\r\n        if (customer.IsSystemAccount)\r\n            throw new NopException($\"System customer account ({customer.SystemName}) could not be deleted\");\r\n\r\n        customer.Deleted = true;\r\n\r\n        if (_customerSettings.SuffixDeletedCustomers)\r\n        {\r\n            if (!string.IsNullOrEmpty(customer.Email))\r\n                customer.Email += NopCustomerServicesDefaults.CustomerDeletedSuffix;\r\n            if (!string.IsNullOrEmpty(customer.Username))\r\n                customer.Username += NopCustomerServicesDefaults.CustomerDeletedSuffix;\r\n        }\r\n\r\n        await _customerRepository.UpdateAsync(customer, false);\r\n        await _customerRepository.DeleteAsync(customer);\r\n    }\r\n\r\n    /// <summary>\r\n    /// Gets a customer\r\n    /// </summary>\r","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/Customers/CustomerService.cs#L324-L360","documentation":"Thrown by DeleteCustomerAsync as a NopException when customer.IsSystemAccount is true. Built-in system accounts (e.g., background task user, search-engine crawler user, admin-built-in) are protected from deletion to keep the platform functional.","triggerScenarios":"Calling DeleteCustomerAsync on a customer whose IsSystemAccount flag is true — typically the built-in system/background accounts identified by a non-empty SystemName.","commonSituations":"A cleanup/maintenance script iterates all customers and tries to delete everyone; an admin attempts to remove a built-in account; a GDPR/anonymization batch not excluding system accounts.","solutions":["Filter out system accounts before deleting: skip customers where IsSystemAccount == true.","If the intent is to anonymize, soft-delete only non-system accounts (the method sets Deleted=true rather than physically removing).","Review why a system account was targeted — usually indicates the batch query is too broad."],"exampleFix":"// before\nforeach (var c in customers)\n    await _customerService.DeleteCustomerAsync(c);\n\n// after\nforeach (var c in customers.Where(x => !x.IsSystemAccount))\n    await _customerService.DeleteCustomerAsync(c);","handlingStrategy":"validation","validationCode":"foreach (var c in customers.Where(x => !x.IsSystemAccount))\n    await _customerService.DeleteCustomerAsync(c);","typeGuard":"static bool IsDeletable(Customer c) => c is not null && !c.IsSystemAccount;","tryCatchPattern":null,"preventionTips":["Always filter out IsSystemAccount in bulk-delete batches.","Hide delete actions for system accounts in the admin UI.","Use soft-delete semantics — the method sets Deleted=true."],"tags":["customer","system-account","delete","security","safety"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}