nopSolutions/nopCommerce · error · ArgumentException

No customer found with the specified id

Error message

No customer found with the specified id

What it means

Thrown by ShoppingCartController.GetCartDetails when ICustomerService.GetCustomerByIdAsync(searchModel.CustomerId) returns null. The action is an AJAX endpoint behind the CURRENT_CARTS_MANAGE permission that expands a customer's current cart; it expects a valid customer id and aborts with ArgumentException if the lookup fails. Because no try-catch wraps the call, the exception surfaces as an HTTP 500 to the grid's data request.

Source

Thrown at src/Presentation/Nop.Web/Areas/Admin/Controllers/ShoppingCartController.cs:64

    }

    [HttpPost]
    [CheckPermission(StandardPermission.Orders.CURRENT_CARTS_MANAGE)]
    public virtual async Task<IActionResult> CurrentCarts(ShoppingCartSearchModel searchModel)
    {
        //prepare model
        var model = await _shoppingCartModelFactory.PrepareShoppingCartListModelAsync(searchModel);

        return Json(model);
    }

    [HttpPost]
    [CheckPermission(StandardPermission.Orders.CURRENT_CARTS_MANAGE)]
    public virtual async Task<IActionResult> GetCartDetails(ShoppingCartItemSearchModel searchModel)
    {
        //try to get a customer with the specified id
        var customer = await _customerService.GetCustomerByIdAsync(searchModel.CustomerId)
                       ?? throw new ArgumentException("No customer found with the specified id");

        //prepare model
        var model = await _shoppingCartModelFactory.PrepareShoppingCartItemListModelAsync(searchModel, customer);

        return Json(model);
    }

    [HttpPost]
    [CheckPermission(StandardPermission.Orders.CURRENT_CARTS_MANAGE)]
    public virtual async Task<IActionResult> DeleteItem(int id)
    {
        await _shoppingCartService.DeleteShoppingCartItemAsync(id);

        return new NullJsonResult();
    }

    #endregion
}

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Refresh the current-carts grid so the customer list reflects the latest data, then expand the cart detail again.
  2. If the customer was intentionally deleted, no action is needed — the orphaned cart will be cleaned up by nopCommerce's maintenance routines.
  3. For programmatic callers, guard with a null check on GetCustomerByIdAsync before calling GetCartDetails and return an empty or no-op result.
  4. Check the customer activity/GDPR deletion log to confirm whether the customer was removed by design.

Example fix

// before
var customer = await _customerService.GetCustomerByIdAsync(searchModel.CustomerId)
               ?? throw new ArgumentException("No customer found with the specified id");

// after
var customer = await _customerService.GetCustomerByIdAsync(searchModel.CustomerId);
if (customer is null)
    return ErrorJson("Customer no longer exists.");
Defensive patterns

Strategy: validation

Validate before calling

var customer = await _customerService.GetCustomerByIdAsync(searchModel.CustomerId);
if (customer is null)
    return Json(new { Data = Enumerable.Empty<object>(), Total = 0 });

Try / catch

try { var result = await shoppingCartController.GetCartDetails(searchModel); }
catch (ArgumentException ex) when (ex.Message.Contains("No customer found"))
{ /* customer purged — return empty cart detail */ }

Prevention

When it happens

Trigger: Expanding a 'current cart' detail row in the admin shopping-cart grid for a customer record that was subsequently deleted, anonymized, or had its id changed. Also reproducible by posting a CustomerId of 0 or a non-existent value from a stale list page, or when a guest customer's record was purged by a scheduled cleanup task.

Common situations: An admin opens the current-carts list, walks away, and the guest-customer record is purged by a background job before they expand the row. A customer was merged or deleted in another admin tab. A plugin or import script removed customer rows between page load and the AJAX detail call.

Related errors


AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13). Data as JSON: /api/errors/02f76aeb64064897. Report an issue: GitHub.