nopSolutions/nopCommerce · error · ArgumentException

No picture found with the specified id

Error message

No picture found with the specified id

What it means

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.

Source

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

    [CheckPermission(StandardPermission.Catalog.PRODUCTS_CREATE_EDIT_DELETE)]
    public virtual async Task<IActionResult> ProductPictureUpdate(ProductPictureModel model)
    {
        //try to get a product picture with the specified id
        var productPicture = await _productService.GetProductPictureByIdAsync(model.Id)
            ?? throw new ArgumentException("No product picture 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(productPicture.ProductId);
            if (product != null && product.VendorId != currentVendor.Id)
                return Content("This is not your product");
        }

        //try to get a picture with the specified id
        var picture = await _pictureService.GetPictureByIdAsync(productPicture.PictureId)
            ?? throw new ArgumentException("No picture found with the specified id");

        await _pictureService.UpdatePictureAsync(picture.Id,
            await _pictureService.LoadPictureBinaryAsync(picture),
            picture.MimeType,
            picture.SeoFilename,
            model.OverrideAltAttribute,
            model.OverrideTitleAttribute);

        productPicture.DisplayOrder = model.DisplayOrder;
        await _productService.UpdateProductPictureAsync(productPicture);

        return new NullJsonResult();
    }

    [HttpPost]
    [CheckPermission(StandardPermission.Catalog.PRODUCTS_CREATE_EDIT_DELETE)]
    public virtual async Task<IActionResult> ProductPictureDelete(int id)
    {

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Run a data-integrity cleanup: delete ProductPicture mappings whose PictureId no longer resolves.
  2. Make picture deletion transactional with its mapping deletion (already done by ProductPictureDelete; ensure no partial paths).
  3. Replace the throw with a null guard that logs the orphan and returns a JSON error or removes the stale mapping.
  4. Add a FK constraint / periodic consistency check between ProductPicture and Picture.

Example fix

// before
var picture = await _pictureService.GetPictureByIdAsync(productPicture.PictureId)
    ?? throw new ArgumentException("No picture found with the specified id");

// after
var picture = await _pictureService.GetPictureByIdAsync(productPicture.PictureId);
if (picture == null)
{
    await _productService.DeleteProductPictureAsync(productPicture); // reap orphaned mapping
    return Json(new { success = false, message = "Underlying picture missing; mapping removed." });
}
Defensive patterns

Strategy: fallback

Validate before calling

var picture = await _pictureService.GetPictureByIdAsync(productPicture.PictureId);
if (picture == null)
{
    await _productService.DeleteProductPictureAsync(productPicture); // reap orphan
    return Json(new { success = false, message = "Underlying picture missing; mapping removed." });
}

Try / catch

try { /* update picture */ }
catch (ArgumentException ex) when (ex.Message.Contains("No picture"))
    return Json(new { success = false, message = ex.Message });

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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