nopSolutions/nopCommerce · error · ArgumentException
No tax category found with the specified id
Error message
No tax category found with the specified id
What it means
Thrown in the CategoryDelete controller action when GetTaxCategoryByIdAsync returns null for the provided id parameter. This is an ArgumentException (not NopException), meaning it indicates a programming or request error rather than a business-rule violation. The action expects a valid tax category ID to delete Avalara-specific generic attributes from.
Source
Thrown at src/Plugins/Nop.Plugin.Tax.Avalara/Controllers/AvalaraTaxController.cs:177
//save tax code type as generic attribute
if (!string.IsNullOrEmpty(model.TypeId) && !model.TypeId.Equals(Guid.Empty.ToString()))
await _genericAttributeService.SaveAttributeAsync(taxCategory, AvalaraTaxDefaults.TaxCodeTypeAttribute, model.TypeId);
return Json(new { Result = true });
}
[HttpPost]
[CheckPermission(StandardPermission.Configuration.MANAGE_TAX_SETTINGS)]
public override async Task<IActionResult> CategoryDelete(int id)
{
//ensure that Avalara tax provider is active
if (!await _taxPluginManager.IsPluginActiveAsync(AvalaraTaxDefaults.SystemName))
return new NullJsonResult();
//try to get a tax category with the specified id
var taxCategory = await _taxCategoryService.GetTaxCategoryByIdAsync(id)
?? throw new ArgumentException("No tax category found with the specified id");
//delete generic attributes
await _genericAttributeService.SaveAttributeAsync<string>(taxCategory, AvalaraTaxDefaults.TaxCodeDescriptionAttribute, null);
await _genericAttributeService.SaveAttributeAsync<string>(taxCategory, AvalaraTaxDefaults.TaxCodeTypeAttribute, null);
await _taxCategoryService.DeleteTaxCategoryAsync(taxCategory);
return new NullJsonResult();
}
[HttpPost, ActionName("Categories")]
[FormValueRequired("importTaxCodes")]
[CheckPermission(StandardPermission.Configuration.MANAGE_TAX_SETTINGS)]
public async Task<IActionResult> ImportTaxCodes()
{
//ensure that Avalara tax provider is active
if (!await _taxPluginManager.IsPluginActiveAsync(AvalaraTaxDefaults.SystemName))
return await Categories();View on GitHub (pinned to 64bdf2ff08)
Solutions
- Refresh the tax categories grid in the admin UI to get current data before attempting delete
- Check if the tax category still exists: SELECT * FROM TaxCategory WHERE Id = <id>
- If already deleted, no action needed — the end state is correct
- Add client-side confirmation and handle 404/409 responses gracefully in the UI
Example fix
// before
var taxCategory = await _taxCategoryService.GetTaxCategoryByIdAsync(id)
?? throw new ArgumentException("No tax category found with the specified id");
// after — return a proper HTTP response instead of throwing
var taxCategory = await _taxCategoryService.GetTaxCategoryByIdAsync(id);
if (taxCategory is null)
return NotFound($"No tax category found with id {id}"); Defensive patterns
Strategy: validation
Validate before calling
// Verify tax category exists before attempting delete
var taxCategory = await _taxCategoryService.GetTaxCategoryByIdAsync(id);
if (taxCategory is null)
return Json(new { error = "Tax category not found — it may have already been deleted" }); Try / catch
// Controller action — catch ArgumentException and return user-friendly response
try
{
await _controller.CategoryDelete(id);
}
catch (ArgumentException ex) when (ex.Message.Contains("tax category"))
{
Response.StatusCode = 404;
return Json(new { error = "Tax category no longer exists" });
} Prevention
- Refresh grid data before performing delete operations to avoid stale references
- Return HTTP 404 instead of throwing ArgumentException for missing records
- Add optimistic concurrency checks to detect concurrent modifications
- Use soft-delete patterns to avoid hard-deletes that cause orphaned references
When it happens
Trigger: An HTTP POST to the CategoryDelete action with an id that does not match any TaxCategory record in the database. This typically comes from a grid delete button in the Avalara tax categories admin UI.
Common situations: The tax category was already deleted by another admin session or concurrent request; stale grid data in the browser references a category that no longer exists; the ID was tampered with in the request; a previous delete failed partway through leaving inconsistent state.
Related errors
- No record found
- "{tcName}" tax category could not be loaded
- Tax provider is not configured
- Failed to delete customer
- Failed to get customer's certificates
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/88d7b55181fb28ea.
Report an issue: GitHub.