{"record":{"id":"4399c3c91d99dc80","repo":"nopSolutions/nopCommerce","slug":"tcname-tax-category-could-not-be-loaded","errorCode":null,"errorMessage":"\"{tcName}\" tax category could not be loaded","messagePattern":"\"(.+?)\" tax category could not be loaded","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/Installation/InstallSampleData.Products.cs","lineNumber":133,"sourceCode":"                return id;\n\n            id = await foo(key);\n            dict[key] = id;\n\n            return id;\n        }\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\"));","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/Installation/InstallSampleData.Products.cs#L115-L151","documentation":"Thrown by getTaxCategoryId during sample-product installation. It looks up a TaxCategory by name via GetFirstEntityIdAsync; a null result means the referenced tax category was never seeded, so products cannot be assigned that tax category. As with the other sample-data lookups, it indicates the base tax-category seeding was skipped or the sample data references a name that does not exist.","triggerScenarios":"Installing sample product data referencing a TaxCategory name not present in the DB; running sample install before the base tax-category seeding; a name mismatch between sample data and seeded categories.","commonSituations":"Partial install missing tax-category seeding; version change where default tax-category names differ; custom sample-data file with wrong names.","solutions":["Run the base installer (which seeds tax categories) before sample product data.","Verify referenced TaxCategory names exist in the DB before sample install.","Correct tax-category names in the sample-data source.","Reinstall from a clean database."],"exampleFix":"// before\nasync tName => await GetFirstEntityIdAsync<TaxCategory>(tc => tc.Name == tName)\n    ?? throw new Exception($\"\\\"{tcName}\\\" tax category could not be loaded\")\n\n// after\nvar id = await GetFirstEntityIdAsync<TaxCategory>(tc => tc.Name == taxCategoryName);\nif (id == 0)\n    throw new InvalidOperationException($\"Tax category '{taxCategoryName}' not found. Seed tax categories first.\");","handlingStrategy":"validation","validationCode":"// Verify referenced tax categories exist before sample install\nvar needed = new[] { \"Tax exempt\", \"Standard\" };\nvar missing = needed.Except(await Table<TaxCategory>().Select(tc => tc.Name).ToListAsync());\nif (missing.Any())\n    throw new InvalidOperationException($\"Missing tax categories: {string.Join(\", \", missing)}\");","typeGuard":"static async Task<bool> TaxCategoryExistsAsync(IRepository<TaxCategory> repo, string name)\n    => await repo.Table.AnyAsync(tc => tc.Name == name);","tryCatchPattern":"try { await getTaxCategoryId(name); }\ncatch (Exception ex) when (ex.Message.Contains(\"tax category could not be loaded\"))\n{ /* log missing name + available categories; abort sample install */ }","preventionTips":["Seed tax categories before installing sample products.","Keep tax-category names in sample data aligned with seeded names.","Reinstall from a clean DB."],"tags":["installation","sample-data","tax-category","seeding","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}