nopSolutions/nopCommerce · error · ArgumentException

No related product found with the specified id

Error message

No related product found with the specified id

What it means

Thrown by the RelatedProductUpdate action when _productService.GetRelatedProductByIdAsync(model.Id) returns null (?? throw new ArgumentException). This inline-edit handler updates a related-product mapping's display order via AJAX. The uncaught ArgumentException surfaces as an HTTP 500 to the grid.

Source

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

        //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)
            ?? throw new ArgumentException("No related product found with the specified id");

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

        relatedProduct.DisplayOrder = model.DisplayOrder;
        await _productService.UpdateRelatedProductAsync(relatedProduct);

        return new NullJsonResult();
    }

    [HttpPost]
    [CheckPermission(StandardPermission.Catalog.PRODUCTS_CREATE_EDIT_DELETE)]

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Reload the related-products grid — the mapping was likely removed.
  2. Confirm the related-product mapping Id still exists before updating.
  3. Return a NullJsonResult or BadRequest when the mapping is null instead of throwing.
  4. In automation, re-fetch the mapping immediately before the update call.

Example fix

// before
var relatedProduct = await _productService.GetRelatedProductByIdAsync(model.Id)
    ?? throw new ArgumentException("No related product found with the specified id");

// after
var relatedProduct = await _productService.GetRelatedProductByIdAsync(model.Id);
if (relatedProduct == null)
    return BadRequest("No related product found with the specified id");
Defensive patterns

Strategy: validation

Validate before calling

// Before updating: confirm the related-product mapping exists
var relatedProduct = await _productService.GetRelatedProductByIdAsync(model.Id);
if (relatedProduct == null)
    return BadRequest("No related product found with the specified id");

Type guard

if (model.Id <= 0) return BadRequest("Invalid related product id");

Try / catch

try { var rp = await _productService.GetRelatedProductByIdAsync(model.Id) ?? throw new ArgumentException(); ... } catch (ArgumentException) { return BadRequest("No related product found"); }

Prevention

When it happens

Trigger: POST to update a related-product mapping whose Id no longer exists — the mapping was deleted in another session, or the grid row is stale.

Common situations: Two admins editing the same product's related products concurrently (one deletes a mapping the other edits); a stale grid row after the underlying mapping was removed; programmatic update of an already-deleted mapping.

Related errors


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