nopSolutions/nopCommerce · warning · NopException

Topic not found

Error message

Topic not found

What it means

Thrown by InitMenuItemModelEntityIdAsync while building an admin menu item model. When a menu item is of type TopicPage, the factory resolves the linked topic via _topicService.GetTopicByIdAsync(entityId); if that returns null the topic record does not exist (deleted, wrong id, or never created) and a NopException is thrown. It is caught locally (line 182) and surfaced only as a UI warning notification, so it does not crash the request. It signals a dangling entity reference: the menu item points at a topic id that the database can no longer resolve.

Source

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

        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");

                    model.CategoryId = category.Id;
                    break;
                }
                case MenuItemType.Vendor:
                {
                    var vendor = await _vendorService.GetVendorByIdAsync(entityId);

                    if (vendor is null || vendor.Deleted)

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Re-open the menu item in the admin UI and re-select a valid topic (the warning is shown and the item is not broken for editing).
  2. If the topic was deleted by mistake, restore it from a backup so the EntityId resolves again.
  3. Run a data-integrity query to find menu items whose TopicPage EntityId no longer matches a row in Topic, and clear or reassign them.
  4. Before deleting a topic, remove or reassign any menu items that reference it.

Example fix

// before
var topic = await _topicService.GetTopicByIdAsync(entityId) ?? throw new NopException("Topic not found");
// after (graceful: skip and warn only)
var topic = await _topicService.GetTopicByIdAsync(entityId);
if (topic is null)
{
    _notificationService.WarningNotification($"Topic with id {entityId} was not found; menu item skipped.");
    return;
}
model.TopicId = topic.Id;
Defensive patterns

Strategy: validation

Validate before calling

// Before building the menu item model, verify the topic exists.
if (model.MenuItemTypeId == (int)MenuItemType.TopicPage)
{
    var topic = await _topicService.GetTopicByIdAsync(entityId);
    if (topic is null)
    {
        _notificationService.WarningNotification($"Topic {entityId} not found; skipping.");
        return;
    }
}

Type guard

// C# has no runtime type guard; use a null check on the loaded entity.
static bool TopicExists(Topic t) => t is not null;

Try / catch

// The factory already catches NopException and shows a warning:
try { /* InitMenuItemModelEntityIdAsync body */ }
catch (NopException ex) { _notificationService.WarningNotification(ex.Message); }

Prevention

When it happens

Trigger: A MenuItem row exists with MenuItemTypeId = TopicPage and an EntityId value for which TopicService.GetTopicByIdAsync returns null. This happens when the linked topic was deleted after the menu item was created, when an admin hand-edited/seeded a bad EntityId, or during import where topic ids were remapped.

Common situations: Migrating/importing menus where topic ids shift; deleting a topic that is still referenced by a menu; multi-store setups where the topic exists in another store context; stale menu items left after a topic cleanup script.

Related errors


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