{"record":{"id":"3a031c2c5e03b90f","repo":"nopSolutions/nopCommerce","slug":"picture-cannot-be-loaded","errorCode":null,"errorMessage":"Picture cannot be loaded","messagePattern":"Picture cannot be loaded","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Plugins/Nop.Plugin.Widgets.Swiper/Controllers/WidgetSwiperController.cs","lineNumber":175,"sourceCode":"\n    [HttpPost]\n    [CheckPermission(StandardPermission.Configuration.MANAGE_WIDGETS)]\n    public async Task<IActionResult> SlideList(SlidesSearchModel slidesSearchModel)\n    {\n        var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync();\n        var slides = await GetSlidesForStoreAsync(storeScope);\n\n        if (slides is null)\n            return Json(new SlideListModel());\n\n        var model = await new SlideListModel().PrepareToGridAsync(slidesSearchModel, slides.ToPagedList(slidesSearchModel), () =>\n        {\n            return slides\n                .Where(s => s.PictureId != 0)\n                .SelectAwait(async item =>\n                {\n                    var picture = (await _pictureService.GetPictureByIdAsync(item.PictureId))\n                        ?? throw new Exception(\"Picture cannot be loaded\");\n\n                    return new PublicSlideModel\n                    {\n                        PictureId = item.PictureId,\n                        PictureUrl = (await _pictureService.GetPictureUrlAsync(picture, 200)).Url,\n                        TitleText = item.TitleText,\n                        AltText = item.AltText,\n                        LinkUrl = item.LinkUrl\n                    };\n                });\n        });\n\n        return Json(model);\n    }\n\n    [HttpPost]\n    [CheckPermission(StandardPermission.Configuration.MANAGE_WIDGETS)]\n    public virtual async Task<IActionResult> SlideDelete(int pictureId)","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Plugins/Nop.Plugin.Widgets.Swiper/Controllers/WidgetSwiperController.cs#L157-L193","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nvar picture = (await _pictureService.GetPictureByIdAsync(item.PictureId))\n    ?? throw new Exception(\"Picture cannot be loaded\");\n\n// after\nvar picture = await _pictureService.GetPictureByIdAsync(item.PictureId);\nif (picture == null)\n    return null; // filtered out by Where(s => s != null) upstream\n","handlingStrategy":"validation","validationCode":"// Before rendering slides, prune/flag any whose PictureId is unresolvable.\nvar validPictureIds = await _pictureService.GetExistingPictureIdsAsync(slides.Select(s => s.PictureId));\nvar safeSlides = slides.Where(s => validPictureIds.Contains(s.PictureId));","typeGuard":"// Narrow to slides with a non-zero, resolvable picture before projecting.\nstatic bool SlideHasValidPicture(Slide s, ISet<int> existingIds)\n    => s.PictureId != 0 && existingIds.Contains(s.PictureId);","tryCatchPattern":"// Wrap the projection so one bad slide doesn't 500 the whole widget.\ntry { /* PrepareToGridAsync(...) */ }\ncatch (Exception ex) when (ex.Message == \"Picture cannot be loaded\")\n{\n    _logger.Warning(ex, \"Swiper slide references a missing picture\");\n    return Json(new SlideListModel());\n}","preventionTips":["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."],"tags":["nopcommerce","widget","picture","stale-reference","swiper"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}