nopSolutions/nopCommerce · error · Exception
Picture cannot be loaded
Error message
Picture cannot be loaded
What it means
Thrown by the Swiper widget controller while rendering the public slide list. After a slide row passes the `PictureId != 0` filter, the controller calls _pictureService.GetPictureByIdAsync and, if that returns null, throws a generic Exception. It means a slide references a PictureId whose row no longer exists in the Picture table (deleted media, stale setting JSON, or a multi-store scope mismatch).
Source
Thrown at src/Plugins/Nop.Plugin.Widgets.Swiper/Controllers/WidgetSwiperController.cs:175
[HttpPost]
[CheckPermission(StandardPermission.Configuration.MANAGE_WIDGETS)]
public async Task<IActionResult> SlideList(SlidesSearchModel slidesSearchModel)
{
var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync();
var slides = await GetSlidesForStoreAsync(storeScope);
if (slides is null)
return Json(new SlideListModel());
var model = await new SlideListModel().PrepareToGridAsync(slidesSearchModel, slides.ToPagedList(slidesSearchModel), () =>
{
return slides
.Where(s => s.PictureId != 0)
.SelectAwait(async item =>
{
var picture = (await _pictureService.GetPictureByIdAsync(item.PictureId))
?? throw new Exception("Picture cannot be loaded");
return new PublicSlideModel
{
PictureId = item.PictureId,
PictureUrl = (await _pictureService.GetPictureUrlAsync(picture, 200)).Url,
TitleText = item.TitleText,
AltText = item.AltText,
LinkUrl = item.LinkUrl
};
});
});
return Json(model);
}
[HttpPost]
[CheckPermission(StandardPermission.Configuration.MANAGE_WIDGETS)]
public virtual async Task<IActionResult> SlideDelete(int pictureId)View on GitHub (pinned to 64bdf2ff08)
Solutions
- Run a DB cleanup that removes or nulls PictureId on slide entries pointing at non-existent Picture rows, then re-save SwiperSettings per store.
- In admin, edit the swiper slides and re-pick a valid picture for the offending slide, then save.
- Guard the projection: skip slides whose picture is null instead of throwing (see exampleFix).
Example fix
// before
var picture = (await _pictureService.GetPictureByIdAsync(item.PictureId))
?? throw new Exception("Picture cannot be loaded");
// after
var picture = await _pictureService.GetPictureByIdAsync(item.PictureId);
if (picture == null)
return null; // filtered out by Where(s => s != null) upstream
Defensive patterns
Strategy: validation
Validate before calling
// Before rendering slides, prune/flag any whose PictureId is unresolvable. var validPictureIds = await _pictureService.GetExistingPictureIdsAsync(slides.Select(s => s.PictureId)); var safeSlides = slides.Where(s => validPictureIds.Contains(s.PictureId));
Type guard
// Narrow to slides with a non-zero, resolvable picture before projecting.
static bool SlideHasValidPicture(Slide s, ISet<int> existingIds)
=> s.PictureId != 0 && existingIds.Contains(s.PictureId); Try / catch
// Wrap the projection so one bad slide doesn't 500 the whole widget.
try { /* PrepareToGridAsync(...) */ }
catch (Exception ex) when (ex.Message == "Picture cannot be loaded")
{
_logger.Warning(ex, "Swiper slide references a missing picture");
return Json(new SlideListModel());
} Prevention
- When deleting a picture, also null/remove PictureId on any slide referencing it.
- Add a DB constraint or scheduled cleanup that drops slide rows with orphaned PictureIds.
- Log which PictureId failed so the operator can repair it quickly.
When it happens
Trigger: GET to the swiper widget grid/list action where PrepareToGridAsync enumerates slides and one slide has a PictureId that GetPictureByIdAsync cannot resolve. Occurs after a picture was deleted from the admin media manager while the slide still points at its old ID.
Common situations: Stale SwiperSettings.Slides JSON persisted per-store pointing at picture IDs that were later removed; importing/exporting stores without syncing media; race between deleting a picture and pruning slide references.
Related errors
- No slides found with the specified picture id
- Picture cannot be loaded
- Email is not valid.
- Unable to connect to the new database. Please try one more t
- Unable to connect to the new database. Please try one more t
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/3a031c2c5e03b90f.
Report an issue: GitHub.