nopSolutions/nopCommerce · error · NopException
Company not selected
Error message
Company not selected
What it means
ExportTaxCodesAsync requires a target company to export tax codes into. It throws when _avalaraTaxSettings.CompanyCode is empty or equals Guid.Empty.ToString(), i.e. no company was selected in the plugin settings. This is a pure configuration precondition, independent of any network call.
Source
Thrown at src/Plugins/Nop.Plugin.Tax.Avalara/Services/AvalaraTaxManager.cs:957
}
return importedTaxCodesNumber;
})).Result;
}
/// <summary>
/// Export current tax codes to Avalara services
/// </summary>
/// <returns>
/// A task that represents the asynchronous operation
/// The task result contains the number of exported tax codes; null in case of error
/// </returns>
public async Task<int?> ExportTaxCodesAsync()
{
return (await HandleFunctionAsync<int?>(async () =>
{
if (string.IsNullOrEmpty(_avalaraTaxSettings.CompanyCode) || _avalaraTaxSettings.CompanyCode.Equals(Guid.Empty.ToString()))
throw new NopException("Company not selected");
//get selected company
var selectedCompany = (await GetAccountCompaniesAsync())
?.FirstOrDefault(company => _avalaraTaxSettings.CompanyCode.Equals(company?.companyCode))
?? throw new NopException("Failed to retrieve company");
//get existing tax codes (only active)
var taxCodes = await ServiceClient.ListTaxCodesByCompanyAsync(selectedCompany.id, "isActive eq true", null, null, null, null)
?? throw new NopException("No response from the service");
var existingTaxCodes = taxCodes.value?.Select(taxCode => taxCode.taxCode).ToList() ?? new List<string>();
//prepare tax codes to export
var taxCodesToExport = await (await _taxCategoryService.GetAllTaxCategoriesAsync()).SelectAwait(async taxCategory => new TaxCodeModel
{
createdDate = DateTime.UtcNow,
description = CommonHelper.EnsureMaximumLength(taxCategory.Name, 255),
isActive = true,View on GitHub (pinned to 64bdf2ff08)
Solutions
- Open the Avalara tax provider settings and select a company.
- Click 'Get account companies' first to populate the dropdown, then choose a company.
- Save the settings before retrying the export.
Example fix
// before
if (string.IsNullOrEmpty(_avalaraTaxSettings.CompanyCode) || _avalaraTaxSettings.CompanyCode.Equals(Guid.Empty.ToString()))
throw new NopException("Company not selected");
// after - point the admin to the remedy
if (string.IsNullOrEmpty(_avalaraTaxSettings.CompanyCode) || _avalaraTaxSettings.CompanyCode.Equals(Guid.Empty.ToString()))
throw new NopException("Company not selected - choose a company in the Avalara provider settings (run 'Get account companies' first)"); Defensive patterns
Strategy: validation
Validate before calling
// Guard the export behind a company-selection check
if (string.IsNullOrEmpty(_avalaraTaxSettings.CompanyCode) ||
_avalaraTaxSettings.CompanyCode.Equals(Guid.Empty.ToString()))
{
throw new NopException("Select a company before exporting tax codes.");
}
await taxManager.ExportTaxCodesAsync(); Type guard
static bool IsCompanySelected(AvalaraTaxSettings s) =>
!string.IsNullOrEmpty(s.CompanyCode) && !s.CompanyCode.Equals(Guid.Empty.ToString()); Prevention
- Run 'Get account companies' and select a company before any export.
- Disable the export button in the UI until a company is selected.
- Validate CompanyCode on settings save.
When it happens
Trigger: An admin triggered 'Export tax codes' while CompanyCode is unset (empty or the Guid.Empty sentinel), typically on a fresh install or after the company dropdown was cleared.
Common situations: Fresh plugin install with no company selected; the company dropdown was never populated because 'Get account companies' was not run first; settings were reset.
Related errors
- Failed to retrieve company
- Archive '{NopCommonDefaults.LocalePatternArchiveName}' to re
- A theme descriptor '{descriptionFile}' has no system name
- A theme with '{themeDescriptor.SystemName}' system name is a
- Plugins.ExchangeRate.EcbExchange.Error
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/f64e684e5086cd7e.
Report an issue: GitHub.