nopSolutions/nopCommerce · error · ArgumentException

Admin.Catalog.Categories.Import.CategoriesArentImported

Error message

Admin.Catalog.Categories.Import.CategoriesArentImported

What it means

Thrown during category XLSX import when one or more categories still cannot be saved after the import's retry passes — typically because their parent category reference could not be resolved (circular or unsatisfied parent dependency). nopCommerce collects the names of the still-unresolved categories and aborts with an ArgumentException.

Source

Thrown at src/Libraries/Nop.Services/ExportImport/ImportManager.cs:3306

            needSave = remove.Any() && saveNextTime.Any();
        }

        //activity log
        await _customerActivityService.InsertActivityAsync("ImportCategories",
            string.Format(await _localizationService.GetResourceAsync("ActivityLog.ImportCategories"), iRow - 2 - saveNextTime.Count));

        if (!saveNextTime.Any())
            return;

        var categoriesName = new List<string>();

        foreach (var rowId in saveNextTime)
        {
            manager.ReadDefaultFromXlsx(defaultWorksheet, rowId);
            categoriesName.Add(manager.GetDefaultProperty("Name").StringValue);
        }

        throw new ArgumentException(string.Format(await _localizationService.GetResourceAsync("Admin.Catalog.Categories.Import.CategoriesArentImported"), string.Join(", ", categoriesName)));
    }

    /// <summary>
    /// Import orders from XLSX file
    /// </summary>
    /// <param name="stream">Stream</param>
    /// <returns>A task that represents the asynchronous operation</returns>
    public virtual async Task ImportOrdersFromXlsxAsync(Stream stream)
    {
        using var workbook = new XLWorkbook(stream);

        var (metadata, worksheet) = await PrepareImportOrderDataAsync(workbook);

        //performance optimization, load all orders by guid in one SQL request
        var allOrdersByGuids = await _orderService.GetOrdersByGuidsAsync(metadata.AllOrderGuids.ToArray());

        //performance optimization, load all customers by guid in one SQL request
        var allCustomersByGuids = await _customerService.GetCustomersByGuidsAsync(metadata.AllCustomerGuids.ToArray());

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Reorder the spreadsheet so parent categories appear before their children, then re-import.
  2. Fix any parent-category references that point to non-existent or misspelled names.
  3. Break any circular parent references in the file.
  4. Import the file in multiple passes, creating top-level parents first.

Example fix

// before — child row appears before its parent in the file
Row 1: Name="Shoes",      ParentCategory="Apparel"
Row 2: Name="Apparel",    ParentCategory=""

// after — parents first
Row 1: Name="Apparel",    ParentCategory=""
Row 2: Name="Shoes",      ParentCategory="Apparel"
Defensive patterns

Strategy: validation

Validate before calling

// Detect unresolved parent-category references before importing categories
// Order rows so parents precede children; flag any child whose parent is not yet created
var ordered = new List<CategoryRow>();
var pending = rows.ToList();
bool changed;
do {
    changed = false;
    for (int i = pending.Count - 1; i >= 0; i--)
    {
        var r = pending[i];
        if (string.IsNullOrWhiteSpace(r.ParentName) || ordered.Any(o => o.Name == r.ParentName))
        { ordered.Insert(0, r); pending.RemoveAt(i); changed = true; }
    }
} while (changed);
if (pending.Any())
    return BadRequest($"These categories have unresolved parents: {string.Join(", ", pending.Select(p => p.Name))}");
await _importManager.ImportCategoriesFromXlsxAsync(stream);

Try / catch

try { await _importManager.ImportCategoriesFromXlsxAsync(stream); }
catch (ArgumentException ex) when (ex.Message.Contains("CategoriesArentImported"))
{ /* show the stuck category names and ask the user to reorder/fix parents */ }

Prevention

When it happens

Trigger: Calling the category import path where saveNextTime is non-empty after the import loop — i.e. some rows never got a resolvable parent category. The method reads each stuck row's Name and throws listing them.

Common situations: A category row references a parent that does not exist or is imported later in the file; circular parent references; the file ordering puts children before parents; parent category names have typos/whitespace so they never match.

Related errors


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