nopSolutions/nopCommerce · error · Exception

Video cannot be loaded

Error message

Video cannot be loaded

What it means

Thrown while preparing the admin product-video grid (PrepareProductVideoListModel). For each ProductVideo mapping row the factory loads the Video via _videoService.GetVideoByIdAsync(productVideo.VideoId); if null, it throws a bare System.Exception that propagates. It indicates the ProductVideoMapping join references a VideoId with no corresponding Video record. Same structural defect as the picture variant: an orphaned mapping row.

Source

Thrown at src/Presentation/Nop.Web/Areas/Admin/Factories/ProductModelFactory.cs:1630

    public virtual async Task<ProductVideoListModel> PrepareProductVideoListModelAsync(ProductVideoSearchModel searchModel, Product product)
    {
        ArgumentNullException.ThrowIfNull(searchModel);
        ArgumentNullException.ThrowIfNull(product);

        //get product videos
        var productVideos = (await _productService.GetProductVideosByProductIdAsync(product.Id)).ToPagedList(searchModel);

        //prepare grid model
        var model = await new ProductVideoListModel().PrepareToGridAsync(searchModel, productVideos, () =>
        {
            return productVideos.SelectAwait(async productVideo =>
            {
                //fill in model values from the entity
                var productVideoModel = productVideo.ToModel<ProductVideoModel>();

                //fill in additional values (not existing in the entity)
                var video = (await _videoService.GetVideoByIdAsync(productVideo.VideoId))
                    ?? throw new Exception("Video cannot be loaded");

                productVideoModel.VideoUrl = video.VideoUrl;

                return productVideoModel;
            });
        });

        return model;
    }

    /// <summary>
    /// Prepare paged product specification attribute list model
    /// </summary>
    /// <param name="searchModel">Product specification attribute search model</param>
    /// <param name="product">Product</param>
    /// <returns>
    /// A task that represents the asynchronous operation
    /// The task result contains the product specification attribute list model

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Remove or repair the orphaned ProductVideoMapping rows whose VideoId lacks a Video record.
  2. Re-upload the missing video and re-attach it to the product.
  3. Integrity check: SELECT * FROM Product_Video_Mapping pvm LEFT JOIN Video v ON v.Id = pvm.VideoId WHERE v.Id IS NULL; delete those rows.
  4. Restore the Video table from backup if several are missing.

Example fix

// before
var video = (await _videoService.GetVideoByIdAsync(productVideo.VideoId))
    ?? throw new Exception("Video cannot be loaded");
// after (skip broken row)
var video = await _videoService.GetVideoByIdAsync(productVideo.VideoId);
if (video is null)
{
    await _logger.WarningAsync($"ProductVideo mapping {productVideo.Id} references missing video {productVideo.VideoId}");
    return null;
}
Defensive patterns

Strategy: validation

Validate before calling

// Confirm each video mapping resolves before building the grid.
var productVideos = await _productService.GetProductVideosByProductIdAsync(product.Id);
var orphans = productVideos.Where(pv => (await _videoService.GetVideoByIdAsync(pv.VideoId)) is null).ToList();
if (orphans.Any())
    await _logger.WarningAsync($"{orphans.Count} product-video mappings reference missing videos.");

Type guard

static bool VideoResolved(Video v) => v is not null;

Try / catch

try { /* PrepareToGridAsync body */ }
catch (Exception ex) when (ex.Message == "Video cannot be loaded")
{
    await _logger.WarningAsync(ex.Message, ex);
    /* return empty/partial grid */
}

Prevention

When it happens

Trigger: A ProductVideoMapping row has a VideoId for which VideoService.GetVideoByIdAsync returns null. Caused by a video record deleted while its product mapping remained, or a failed video ingestion that left a dangling mapping.

Common situations: Video record hard-deleted from DB without removing ProductVideoMapping; failed upload leaving orphan mapping; storage/backend migration dropping video entries; video plugin uninstall removing Video rows but not mappings.

Related errors


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