{"record":{"id":"5c9663d8f0ccc275","repo":"nopSolutions/nopCommerce","slug":"cname-category-could-not-be-loaded","errorCode":null,"errorMessage":"\"{cName}\" category could not be loaded","messagePattern":"\"(.+?)\" category could not be loaded","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/Installation/InstallSampleData.Products.cs","lineNumber":139,"sourceCode":"        }\n\n        async Task<int> getProductTemplate(string templateName)\n        {\n            return await getAndSaveId(productTemplates, templateName,\n                async tName => await GetFirstEntityIdAsync<ProductTemplate>(pt => pt.Name == tName) ??\n                    throw new Exception($\"\\\"{tName}\\\" template could not be loaded\"));\n        }\n\n        async Task<int> getTaxCategoryId(string taxCategoryName)\n        {\n            return await getAndSaveId(taxCategories, taxCategoryName, async tcName => await GetFirstEntityIdAsync<TaxCategory>(tc => tc.Name == tcName) ??\n                throw new Exception($\"\\\"{tcName}\\\" tax category could not be loaded\"));\n        }\n\n        async Task<int> getCategoryId(string categoryName)\n        {\n            return await getAndSaveId(categories, categoryName, async cName => await GetFirstEntityIdAsync<Category>(c => c.Name == cName) ??\n                throw new Exception($\"\\\"{cName}\\\" category could not be loaded\"));\n        }\n\n        async Task<int> getManufacturerId(string manufacturerName)\n        {\n            return await getAndSaveId(manufacturers, manufacturerName, async mName => await GetFirstEntityIdAsync<Manufacturer>(m => m.Name == mName) ??\n                throw new Exception($\"\\\"{mName}\\\" manufacturer could not be loaded\"));\n        }\n\n        async Task<int> getProductAttributeId(string productAttributeName)\n        {\n            return await getAndSaveId(productAttributes, productAttributeName, async paName => await GetFirstEntityIdAsync<ProductAttribute>(pa => pa.Name == paName) ??\n                throw new Exception($\"\\\"{paName}\\\" product attribute could not be loaded\"));\n        }\n\n        async Task<int> getProductAvailabilityRangeId(string productAvailabilityRangeName)\n        {\n            return await getAndSaveId(productAvailabilityRanges, productAvailabilityRangeName, async parName => await GetFirstEntityIdAsync<ProductAvailabilityRange>(par => par.Name == parName) ??\n                throw new Exception($\"\\\"{parName}\\\" product availability range could not be loaded\"));","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/Installation/InstallSampleData.Products.cs#L121-L157","documentation":"Thrown by getCategoryId during sample-product installation. It resolves a Category by name; if none matches, sample products cannot be assigned to a category, so it throws. This means the referenced category name was not seeded (categories are typically part of base/sample setup) or the sample data uses a name that does not exist.","triggerScenarios":"Installing sample products that reference a Category name absent from the DB; running product sample install before category seeding; name mismatch between sample data and seeded categories.","commonSituations":"Partial install missing category seeding; reordering of install steps; a custom sample-data file with wrong category names.","solutions":["Run the category-seeding install step before sample product install.","Verify referenced Category names exist before installing sample products.","Fix category-name typos in the sample-data source.","Reinstall from a clean database."],"exampleFix":"// before\nasync cName => await GetFirstEntityIdAsync<Category>(c => c.Name == cName)\n    ?? throw new Exception($\"\\\"{cName}\\\" category could not be loaded\")\n\n// after\nvar id = await GetFirstEntityIdAsync<Category>(c => c.Name == categoryName);\nif (id == 0)\n    throw new InvalidOperationException($\"Category '{categoryName}' not found. Seed categories first.\");","handlingStrategy":"validation","validationCode":"// Verify referenced categories exist before sample install\nvar needed = new[] { \"Computers\", \"Electronics\" };\nvar missing = needed.Except(await Table<Category>().Select(c => c.Name).ToListAsync());\nif (missing.Any())\n    throw new InvalidOperationException($\"Missing categories: {string.Join(\", \", missing)}\");","typeGuard":"static async Task<bool> CategoryExistsAsync(IRepository<Category> repo, string name)\n    => await repo.Table.AnyAsync(c => c.Name == name);","tryCatchPattern":"try { await getCategoryId(name); }\ncatch (Exception ex) when (ex.Message.Contains(\"category could not be loaded\"))\n{ /* log missing name + available categories; abort sample install */ }","preventionTips":["Seed categories before installing sample products.","Keep category names in sample data aligned with seeded names.","Reinstall from a clean DB."],"tags":["installation","sample-data","category","seeding","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}