nopSolutions/nopCommerce · error · NopException

Product not found

Error message

Product not found

What it means

Thrown by MenuModelFactory when building a menu-item model for MenuItemType.Product and the referenced product is null or marked Deleted. Unlike the controller ArgumentExceptions, this is a NopException thrown from a factory (not a controller action), meaning it fires during model preparation rather than at the request boundary. The factory first guards entityId with ArgumentOutOfRangeException.ThrowIfZero, then for the Product case checks both null and the Deleted soft-delete flag before throwing.

Source

Thrown at src/Presentation/Nop.Web/Areas/Admin/Factories/MenuModelFactory.cs:136

    /// <param name="model">Menu item model</param>
    /// <param name="entityId">Entity identifier</param>
    /// <returns>
    /// A task that represents the asynchronous operation
    /// </returns>
    protected virtual async Task InitMenuItemModelEntityIdAsync(MenuItemModel model, int entityId)
    {
        ArgumentOutOfRangeException.ThrowIfZero(entityId);

        try
        {
            switch ((MenuItemType)model.MenuItemTypeId)
            {
                case MenuItemType.Product:
                {
                    var product = await _productService.GetProductByIdAsync(entityId);

                    if (product is null || product.Deleted)
                        throw new NopException("Product not found");

                    model.ProductName = product.Name;
                    model.ProductId = product.Id;
                    break;
                }
                case MenuItemType.TopicPage:
                {
                    var topic = await _topicService.GetTopicByIdAsync(entityId) ?? throw new NopException("Topic not found");
                    model.TopicId = topic.Id;
                    break;
                }
                case MenuItemType.Category:
                {
                    var category = await _categoryService.GetCategoryByIdAsync(entityId);

                    if (category is null || category.Deleted)
                        throw new NopException("Category not found");

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Edit the menu item in the admin menu management UI and point it to an existing, non-deleted product, or remove the menu item.
  2. Restore or re-create the deleted product if it was removed in error, then the menu item resolves normally.

Example fix

// before
if (product is null || product.Deleted)
    throw new NopException("Product not found");

// after
if (product is null || product.Deleted)
    return ErrorJson("Referenced product no longer exists. Reassign or remove this menu item.");
Defensive patterns

Strategy: try-catch

Validate before calling

// Before preparing the menu-item model, verify the product exists and is not deleted
if ((MenuItemType)model.MenuItemTypeId == MenuItemType.Product)
{
    var product = await _productService.GetProductByIdAsync(entityId);
    if (product is null || product.Deleted)
        return ErrorJson("Referenced product no longer exists.");
}

Type guard

// C# extension/guard for soft-delete-safe product check
static bool ProductIsUsable(Product product)
    => product is not null && !product.Deleted;

Try / catch

try { await menuModelFactory.PrepareMenuItemModelAsync(model, entityId); }
catch (NopException ex) when (ex.Message == "Product not found")
{ /* linked product was deleted — prompt user to reassign the menu item */ }

Prevention

When it happens

Trigger: Configuring a custom menu item of type Product whose referenced ProductId was deleted (soft-deleted with Deleted=true) after the menu item was created. Also fires if the product id points to a record that never existed or was hard-purged. Triggered during menu rendering or menu-item model preparation, not during a direct CRUD operation.

Common situations: A merchant links a menu item to a product, then later deletes that product (soft delete); the next time the menu is rendered or edited, the factory throws. A product import/merge changed the product id, orphaning the menu item reference. A product was unpublished and then deleted by an admin unaware of the menu dependency.

Related errors


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