{"record":{"id":"58821896faed2049","repo":"nopSolutions/nopCommerce","slug":"admin-catalog-categories-import-categoriesarentimp","errorCode":null,"errorMessage":"Admin.Catalog.Categories.Import.CategoriesArentImported","messagePattern":"Admin\\.Catalog\\.Categories\\.Import\\.CategoriesArentImported","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/ExportImport/ImportManager.cs","lineNumber":3306,"sourceCode":"            needSave = remove.Any() && saveNextTime.Any();\r\n        }\r\n\r\n        //activity log\r\n        await _customerActivityService.InsertActivityAsync(\"ImportCategories\",\r\n            string.Format(await _localizationService.GetResourceAsync(\"ActivityLog.ImportCategories\"), iRow - 2 - saveNextTime.Count));\r\n\r\n        if (!saveNextTime.Any())\r\n            return;\r\n\r\n        var categoriesName = new List<string>();\r\n\r\n        foreach (var rowId in saveNextTime)\r\n        {\r\n            manager.ReadDefaultFromXlsx(defaultWorksheet, rowId);\r\n            categoriesName.Add(manager.GetDefaultProperty(\"Name\").StringValue);\r\n        }\r\n\r\n        throw new ArgumentException(string.Format(await _localizationService.GetResourceAsync(\"Admin.Catalog.Categories.Import.CategoriesArentImported\"), string.Join(\", \", categoriesName)));\r\n    }\r\n\r\n    /// <summary>\r\n    /// Import orders from XLSX file\r\n    /// </summary>\r\n    /// <param name=\"stream\">Stream</param>\r\n    /// <returns>A task that represents the asynchronous operation</returns>\r\n    public virtual async Task ImportOrdersFromXlsxAsync(Stream stream)\r\n    {\r\n        using var workbook = new XLWorkbook(stream);\r\n\r\n        var (metadata, worksheet) = await PrepareImportOrderDataAsync(workbook);\r\n\r\n        //performance optimization, load all orders by guid in one SQL request\r\n        var allOrdersByGuids = await _orderService.GetOrdersByGuidsAsync(metadata.AllOrderGuids.ToArray());\r\n\r\n        //performance optimization, load all customers by guid in one SQL request\r\n        var allCustomersByGuids = await _customerService.GetCustomersByGuidsAsync(metadata.AllCustomerGuids.ToArray());\r","sourceCodeStart":3288,"sourceCodeEnd":3324,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/ExportImport/ImportManager.cs#L3288-L3324","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Reorder the spreadsheet so parent categories appear before their children, then re-import.","Fix any parent-category references that point to non-existent or misspelled names.","Break any circular parent references in the file.","Import the file in multiple passes, creating top-level parents first."],"exampleFix":"// before — child row appears before its parent in the file\nRow 1: Name=\"Shoes\",      ParentCategory=\"Apparel\"\nRow 2: Name=\"Apparel\",    ParentCategory=\"\"\n\n// after — parents first\nRow 1: Name=\"Apparel\",    ParentCategory=\"\"\nRow 2: Name=\"Shoes\",      ParentCategory=\"Apparel\"","handlingStrategy":"validation","validationCode":"// Detect unresolved parent-category references before importing categories\n// Order rows so parents precede children; flag any child whose parent is not yet created\nvar ordered = new List<CategoryRow>();\nvar pending = rows.ToList();\nbool changed;\ndo {\n    changed = false;\n    for (int i = pending.Count - 1; i >= 0; i--)\n    {\n        var r = pending[i];\n        if (string.IsNullOrWhiteSpace(r.ParentName) || ordered.Any(o => o.Name == r.ParentName))\n        { ordered.Insert(0, r); pending.RemoveAt(i); changed = true; }\n    }\n} while (changed);\nif (pending.Any())\n    return BadRequest($\"These categories have unresolved parents: {string.Join(\", \", pending.Select(p => p.Name))}\");\nawait _importManager.ImportCategoriesFromXlsxAsync(stream);","typeGuard":null,"tryCatchPattern":"try { await _importManager.ImportCategoriesFromXlsxAsync(stream); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"CategoriesArentImported\"))\n{ /* show the stuck category names and ask the user to reorder/fix parents */ }","preventionTips":["Order category rows top-down: parents before children.","Ensure parent-category names match exactly (case/whitespace).","Import in multiple passes, top-level parents first."],"tags":["import","catalog","categories","hierarchy","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}