{"record":{"id":"58943f5ee6da1b06","repo":"nopSolutions/nopCommerce","slug":"category-not-found","errorCode":null,"errorMessage":"Category not found","messagePattern":"Category not found","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"warning","filePath":"src/Presentation/Nop.Web/Areas/Admin/Factories/MenuModelFactory.cs","lineNumber":153,"sourceCode":"                    if (product is null || product.Deleted)\n                        throw new NopException(\"Product not found\");\n\n                    model.ProductName = product.Name;\n                    model.ProductId = product.Id;\n                    break;\n                }\n                case MenuItemType.TopicPage:\n                {\n                    var topic = await _topicService.GetTopicByIdAsync(entityId) ?? throw new NopException(\"Topic not found\");\n                    model.TopicId = topic.Id;\n                    break;\n                }\n                case MenuItemType.Category:\n                {\n                    var category = await _categoryService.GetCategoryByIdAsync(entityId);\n\n                    if (category is null || category.Deleted)\n                        throw new NopException(\"Category not found\");\n\n                    model.CategoryId = category.Id;\n                    break;\n                }\n                case MenuItemType.Vendor:\n                {\n                    var vendor = await _vendorService.GetVendorByIdAsync(entityId);\n\n                    if (vendor is null || vendor.Deleted)\n                        throw new NopException(\"Manufacturer not found\");\n\n                    model.VendorId = vendor.Id;\n                    break;\n                }\n                case MenuItemType.Manufacturer:\n                {\n                    var manufacturer = await _manufacturerService.GetManufacturerByIdAsync(entityId);\n","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web/Areas/Admin/Factories/MenuModelFactory.cs#L135-L171","documentation":"Thrown while resolving a menu item of type Category in InitMenuItemModelEntityIdAsync. The factory loads the category by EntityId and, if it is null OR its Deleted flag is true, throws NopException(\"Category not found\"). The exception is caught at line 182 and shown as a warning notification. It guards against both a missing category record and a soft-deleted category, since nopCommerce categories use an IsDeleted (Deleted) flag rather than physical deletion.","triggerScenarios":"A Category menu item references a CategoryId that was soft-deleted (Deleted = true) or never existed (null). Triggered by GetCategoryByIdAsync returning a Deleted entity, e.g. after an admin deleted the category but left the menu item in place.","commonSituations":"Category deleted via admin while still referenced by a custom menu; bulk category deletion scripts that ignore menu references; staging-to-production sync that drops categories but keeps menus; multi-store where the category is scoped to a different store.","solutions":["Edit the menu item in admin and pick a non-deleted category.","Undelete the category if deletion was unintended (set Deleted = false) or restore from backup.","Add a cleanup step to your category-deletion flow that also removes/reassigns dependent menu items.","Run a query joining MenuItem (Category type) to Category where Category.Deleted = 1 and fix the dangling rows."],"exampleFix":"// before\nvar category = await _categoryService.GetCategoryByIdAsync(entityId);\nif (category is null || category.Deleted)\n    throw new NopException(\"Category not found\");\n// after (treat soft-deleted same as missing, log entity id)\nvar category = await _categoryService.GetCategoryByIdAsync(entityId);\nif (category is null || category.Deleted)\n{\n    _notificationService.WarningNotification($\"Category {entityId} is missing or deleted.\");\n    return;\n}","handlingStrategy":"validation","validationCode":"// Validate category exists and is not soft-deleted before initializing the menu item.\nif (model.MenuItemTypeId == (int)MenuItemType.Category)\n{\n    var category = await _categoryService.GetCategoryByIdAsync(entityId);\n    if (category is null || category.Deleted)\n    {\n        _notificationService.WarningNotification($\"Category {entityId} not found or deleted.\");\n        return;\n    }\n}","typeGuard":"static bool CategoryUsable(Category c) => c is not null && !c.Deleted;","tryCatchPattern":"try { /* category case */ }\ncatch (NopException ex) { _notificationService.WarningNotification(ex.Message); }","preventionTips":["Hook menu-item cleanup into the category delete action.","Remember categories are soft-deleted (Deleted flag), so a present-but-deleted row still fails this check.","Validate the category id at menu-item save time."],"tags":["nopcommerce","admin","menu","category","soft-delete","data-integrity"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}