{"record":{"id":"12b15c5976684eb7","repo":"nopSolutions/nopCommerce","slug":"no-picture-found-with-the-specified-id","errorCode":null,"errorMessage":"No picture found with the specified id","messagePattern":"No picture found with the specified id","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Presentation/Nop.Web/Areas/Admin/Controllers/ProductController.cs","lineNumber":2216,"sourceCode":"    [CheckPermission(StandardPermission.Catalog.PRODUCTS_CREATE_EDIT_DELETE)]\n    public virtual async Task<IActionResult> ProductPictureUpdate(ProductPictureModel model)\n    {\n        //try to get a product picture with the specified id\n        var productPicture = await _productService.GetProductPictureByIdAsync(model.Id)\n            ?? throw new ArgumentException(\"No product picture 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(productPicture.ProductId);\n            if (product != null && product.VendorId != currentVendor.Id)\n                return Content(\"This is not your product\");\n        }\n\n        //try to get a picture with the specified id\n        var picture = await _pictureService.GetPictureByIdAsync(productPicture.PictureId)\n            ?? throw new ArgumentException(\"No picture found with the specified id\");\n\n        await _pictureService.UpdatePictureAsync(picture.Id,\n            await _pictureService.LoadPictureBinaryAsync(picture),\n            picture.MimeType,\n            picture.SeoFilename,\n            model.OverrideAltAttribute,\n            model.OverrideTitleAttribute);\n\n        productPicture.DisplayOrder = model.DisplayOrder;\n        await _productService.UpdateProductPictureAsync(productPicture);\n\n        return new NullJsonResult();\n    }\n\n    [HttpPost]\n    [CheckPermission(StandardPermission.Catalog.PRODUCTS_CREATE_EDIT_DELETE)]\n    public virtual async Task<IActionResult> ProductPictureDelete(int id)\n    {","sourceCodeStart":2198,"sourceCodeEnd":2234,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web/Areas/Admin/Controllers/ProductController.cs#L2198-L2234","documentation":"Thrown later in ProductPictureUpdate when _pictureService.GetPictureByIdAsync(productPicture.PictureId) returns null. The ProductPicture mapping row exists, but the Picture it references is gone — an orphaned foreign key. The code then updates alt/title on this picture.","triggerScenarios":"ProductPicture row present while its Picture record was deleted directly (DB-level cleanup, partial delete, or a failed transaction that removed only the picture). The mapping survived but its target did not.","commonSituations":"Custom scripts that delete from Picture without cleaning ProductPicture_Mapping. A crashed ProductPictureDelete that removed the picture but left the mapping. Storage/picture table pruning by maintenance jobs.","solutions":["Run a data-integrity cleanup: delete ProductPicture mappings whose PictureId no longer resolves.","Make picture deletion transactional with its mapping deletion (already done by ProductPictureDelete; ensure no partial paths).","Replace the throw with a null guard that logs the orphan and returns a JSON error or removes the stale mapping.","Add a FK constraint / periodic consistency check between ProductPicture and Picture."],"exampleFix":"// before\nvar picture = await _pictureService.GetPictureByIdAsync(productPicture.PictureId)\n    ?? throw new ArgumentException(\"No picture found with the specified id\");\n\n// after\nvar picture = await _pictureService.GetPictureByIdAsync(productPicture.PictureId);\nif (picture == null)\n{\n    await _productService.DeleteProductPictureAsync(productPicture); // reap orphaned mapping\n    return Json(new { success = false, message = \"Underlying picture missing; mapping removed.\" });\n}","handlingStrategy":"fallback","validationCode":"var picture = await _pictureService.GetPictureByIdAsync(productPicture.PictureId);\nif (picture == null)\n{\n    await _productService.DeleteProductPictureAsync(productPicture); // reap orphan\n    return Json(new { success = false, message = \"Underlying picture missing; mapping removed.\" });\n}","typeGuard":null,"tryCatchPattern":"try { /* update picture */ }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"No picture\"))\n    return Json(new { success = false, message = ex.Message });","preventionTips":["Run ProductPicture/Picture consistency cleanup","Delete picture and mapping transactionally","Add an FK/consistency check"],"tags":["nopcommerce","aspnet-mvc","data-integrity","orphaned-fk","not-found","argument-exception"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}