nopSolutions/nopCommerce · error · ArgumentException

No product found with the specified id

Error message

No product found with the specified id

What it means

Thrown by the RelatedProductList grid action when _productService.GetProductByIdAsync(searchModel.ProductId) returns null (?? throw new ArgumentException). This POST action loads the 'Related products' tab grid for a given product via AJAX. The ArgumentException is uncaught locally and propagates as an HTTP 500 / JSON error to the grid.

Source

Thrown at src/Presentation/Nop.Web/Areas/Admin/Controllers/ProductController.cs:1681

    public virtual async Task<IActionResult> RequiredProductAddPopupList(AddRequiredProductSearchModel searchModel)
    {
        //prepare model
        var model = await _productModelFactory.PrepareAddRequiredProductListModelAsync(searchModel);

        return Json(model);
    }

    #endregion

    #region Related products

    [HttpPost]
    [CheckPermission(StandardPermission.Catalog.PRODUCTS_VIEW)]
    public virtual async Task<IActionResult> RelatedProductList(RelatedProductSearchModel searchModel)
    {
        //try to get a product with the specified id
        var product = await _productService.GetProductByIdAsync(searchModel.ProductId)
            ?? throw new ArgumentException("No product found with the specified id");

        //a vendor should have access only to his products
        var currentVendor = await _workContext.GetCurrentVendorAsync();
        if (currentVendor != null && product.VendorId != currentVendor.Id)
            return Content("This is not your product");

        //prepare model
        var model = await _productModelFactory.PrepareRelatedProductListModelAsync(searchModel, product);

        return Json(model);
    }

    [HttpPost]
    [CheckPermission(StandardPermission.Catalog.PRODUCTS_CREATE_EDIT_DELETE)]
    public virtual async Task<IActionResult> RelatedProductUpdate(RelatedProductModel model)
    {
        //try to get a related product with the specified id
        var relatedProduct = await _productService.GetRelatedProductByIdAsync(model.Id)

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Refresh the product list and re-open a valid product — the ID is likely stale or the product deleted.
  2. Verify the ProductId in the request corresponds to an existing product.
  3. When integrating, call GetProductByIdAsync first and handle null gracefully.
  4. Replace the throw with a NullJsonResult or BadRequest for a friendlier grid error.

Example fix

// before
var product = await _productService.GetProductByIdAsync(searchModel.ProductId)
    ?? throw new ArgumentException("No product found with the specified id");

// after
var product = await _productService.GetProductByIdAsync(searchModel.ProductId);
if (product == null)
    return BadRequest("No product found with the specified id");
Defensive patterns

Strategy: validation

Validate before calling

// Before loading the grid: confirm the product exists
var product = await _productService.GetProductByIdAsync(searchModel.ProductId);
if (product == null)
    return BadRequest("No product found with the specified id");

Type guard

if (searchModel.ProductId <= 0) return BadRequest("Invalid product id");

Try / catch

try { var product = await _productService.GetProductByIdAsync(searchModel.ProductId) ?? throw new ArgumentException(); ... } catch (ArgumentException) { return BadRequest("No product found with the specified id"); }

Prevention

When it happens

Trigger: POST to the related-product list with a ProductId that resolves to no product — the product was deleted, the ID is stale, or the request was tampered.

Common situations: Concurrent admin edits where the product is deleted while its edit page is open elsewhere; a stale/bookmarked product URL; integration tests or scripts hitting the endpoint with a non-existent ProductId.

Related errors


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