{"record":{"id":"6fd3a9d500aea976","repo":"nopSolutions/nopCommerce","slug":"no-related-product-found-with-the-specified-id","errorCode":null,"errorMessage":"No related product found with the specified id","messagePattern":"No related product found with the specified id","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Presentation/Nop.Web/Areas/Admin/Controllers/ProductController.cs","lineNumber":1700,"sourceCode":"\n        //a vendor should have access only to his products\n        var currentVendor = await _workContext.GetCurrentVendorAsync();\n        if (currentVendor != null && product.VendorId != currentVendor.Id)\n            return Content(\"This is not your product\");\n\n        //prepare model\n        var model = await _productModelFactory.PrepareRelatedProductListModelAsync(searchModel, product);\n\n        return Json(model);\n    }\n\n    [HttpPost]\n    [CheckPermission(StandardPermission.Catalog.PRODUCTS_CREATE_EDIT_DELETE)]\n    public virtual async Task<IActionResult> RelatedProductUpdate(RelatedProductModel model)\n    {\n        //try to get a related product with the specified id\n        var relatedProduct = await _productService.GetRelatedProductByIdAsync(model.Id)\n            ?? throw new ArgumentException(\"No related product found with the specified id\");\n\n        //a vendor should have access only to his products\n        var currentVendor = await _workContext.GetCurrentVendorAsync();\n        if (currentVendor != null)\n        {\n            var product = await _productService.GetProductByIdAsync(relatedProduct.ProductId1);\n            if (product != null && product.VendorId != currentVendor.Id)\n                return Content(\"This is not your product\");\n        }\n\n        relatedProduct.DisplayOrder = model.DisplayOrder;\n        await _productService.UpdateRelatedProductAsync(relatedProduct);\n\n        return new NullJsonResult();\n    }\n\n    [HttpPost]\n    [CheckPermission(StandardPermission.Catalog.PRODUCTS_CREATE_EDIT_DELETE)]","sourceCodeStart":1682,"sourceCodeEnd":1718,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web/Areas/Admin/Controllers/ProductController.cs#L1682-L1718","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Reload the related-products grid — the mapping was likely removed.","Confirm the related-product mapping Id still exists before updating.","Return a NullJsonResult or BadRequest when the mapping is null instead of throwing.","In automation, re-fetch the mapping immediately before the update call."],"exampleFix":"// before\nvar relatedProduct = await _productService.GetRelatedProductByIdAsync(model.Id)\n    ?? throw new ArgumentException(\"No related product found with the specified id\");\n\n// after\nvar relatedProduct = await _productService.GetRelatedProductByIdAsync(model.Id);\nif (relatedProduct == null)\n    return BadRequest(\"No related product found with the specified id\");","handlingStrategy":"validation","validationCode":"// Before updating: confirm the related-product mapping exists\nvar relatedProduct = await _productService.GetRelatedProductByIdAsync(model.Id);\nif (relatedProduct == null)\n    return BadRequest(\"No related product found with the specified id\");","typeGuard":"if (model.Id <= 0) return BadRequest(\"Invalid related product id\");","tryCatchPattern":"try { var rp = await _productService.GetRelatedProductByIdAsync(model.Id) ?? throw new ArgumentException(); ... } catch (ArgumentException) { return BadRequest(\"No related product found\"); }","preventionTips":["Reload the related-products grid before inline-editing a possibly stale row.","Re-fetch the mapping immediately before update in automation.","Return NullJsonResult/BadRequest on a missing mapping instead of throwing."],"tags":["nopcommerce","admin","product","related-products","entity-not-found","argumentexception","ajax-grid"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}