nopSolutions/nopCommerce · warning · ArgumentException

No category found with the specified id

Error message

No category found with the specified id

What it means

Thrown by CategoryController.ProductList (permission: CATEGORIES_VIEW). The product-grid datasource loads the parent category by searchModel.CategoryId and throws ArgumentException if absent. The category was deleted or the id is invalid for the current scope.

Solutions

  1. Reopen the category from the list so the product grid references a current CategoryId.
  2. Return an empty product list instead of throwing when the parent category is missing.
  3. Audit client-side code that may retain a stale CategoryId across navigation.

Example fix

// before
var category = await _categoryService.GetCategoryByIdAsync(searchModel.CategoryId)
    ?? throw new ArgumentException("No category found with the specified id");

// after
var category = await _categoryService.GetCategoryByIdAsync(searchModel.CategoryId);
if (category == null)
    return Json(new CategoryProductListModel());
Defensive patterns

Strategy: validation

Validate before calling

// Validate category exists before listing its products.
var category = await _categoryService.GetCategoryByIdAsync(searchModel.CategoryId);
if (category == null) return Json(new CategoryProductListModel());

Type guard

static bool CategoryExists(Category c) => c is not null;

Try / catch

try { /* ProductList body */ }
catch (ArgumentException ex) when (ex.Message.Contains("category"))
{
    return Json(new CategoryProductListModel());
}

Prevention

When it happens

Trigger: POST ProductList with a CategoryId that GetCategoryByIdAsync cannot find — parent category removed while its product tab was open, or a stale/tampered id.

Common situations: Concurrent catalog edits; category deleted in another tab; UI caching an old CategoryId after navigation.

Related errors


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

Appendix: source

Thrown at src/Presentation/Nop.Web/Areas/Admin/Controllers/CategoryController.cs:464

        }
        catch (Exception exc)
        {
            await _notificationService.ErrorNotificationAsync(exc);
            return RedirectToAction("List");
        }
    }

    #endregion

    #region Products

    [HttpPost]
    [CheckPermission(StandardPermission.Catalog.CATEGORIES_VIEW)]
    public virtual async Task<IActionResult> ProductList(CategoryProductSearchModel searchModel)
    {
        //try to get a category with the specified id
        var category = await _categoryService.GetCategoryByIdAsync(searchModel.CategoryId)
            ?? throw new ArgumentException("No category found with the specified id");

        //prepare model
        var model = await _categoryModelFactory.PrepareCategoryProductListModelAsync(searchModel, category);

        return Json(model);
    }

    [CheckPermission(StandardPermission.Catalog.CATEGORIES_CREATE_EDIT_DELETE)]
    public virtual async Task<IActionResult> ProductUpdate(CategoryProductModel model)
    {
        //try to get a product category with the specified id
        var productCategory = await _categoryService.GetProductCategoryByIdAsync(model.Id)
            ?? throw new ArgumentException("No product category mapping found with the specified id");

        //fill entity from product
        productCategory = model.ToEntity(productCategory);
        await _categoryService.UpdateProductCategoryAsync(productCategory);

View on GitHub (pinned to 64bdf2ff08)