{"record":{"id":"f64e684e5086cd7e","repo":"nopSolutions/nopCommerce","slug":"company-not-selected","errorCode":null,"errorMessage":"Company not selected","messagePattern":"Company not selected","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Plugins/Nop.Plugin.Tax.Avalara/Services/AvalaraTaxManager.cs","lineNumber":957,"sourceCode":"            }\n\n            return importedTaxCodesNumber;\n        })).Result;\n    }\n\n    /// <summary>\n    /// Export current tax codes to Avalara services\n    /// </summary>\n    /// <returns>\n    /// A task that represents the asynchronous operation\n    /// The task result contains the number of exported tax codes; null in case of error\n    /// </returns>\n    public async Task<int?> ExportTaxCodesAsync()\n    {\n        return (await HandleFunctionAsync<int?>(async () =>\n        {\n            if (string.IsNullOrEmpty(_avalaraTaxSettings.CompanyCode) || _avalaraTaxSettings.CompanyCode.Equals(Guid.Empty.ToString()))\n                throw new NopException(\"Company not selected\");\n\n            //get selected company\n            var selectedCompany = (await GetAccountCompaniesAsync())\n                ?.FirstOrDefault(company => _avalaraTaxSettings.CompanyCode.Equals(company?.companyCode))\n                ?? throw new NopException(\"Failed to retrieve company\");\n\n            //get existing tax codes (only active)\n            var taxCodes = await ServiceClient.ListTaxCodesByCompanyAsync(selectedCompany.id, \"isActive eq true\", null, null, null, null)\n                ?? throw new NopException(\"No response from the service\");\n\n            var existingTaxCodes = taxCodes.value?.Select(taxCode => taxCode.taxCode).ToList() ?? new List<string>();\n\n            //prepare tax codes to export\n            var taxCodesToExport = await (await _taxCategoryService.GetAllTaxCategoriesAsync()).SelectAwait(async taxCategory => new TaxCodeModel\n            {\n                createdDate = DateTime.UtcNow,\n                description = CommonHelper.EnsureMaximumLength(taxCategory.Name, 255),\n                isActive = true,","sourceCodeStart":939,"sourceCodeEnd":975,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Plugins/Nop.Plugin.Tax.Avalara/Services/AvalaraTaxManager.cs#L939-L975","documentation":"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.","triggerScenarios":"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.","commonSituations":"Fresh plugin install with no company selected; the company dropdown was never populated because 'Get account companies' was not run first; settings were reset.","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."],"exampleFix":"// before\nif (string.IsNullOrEmpty(_avalaraTaxSettings.CompanyCode) || _avalaraTaxSettings.CompanyCode.Equals(Guid.Empty.ToString()))\n    throw new NopException(\"Company not selected\");\n\n// after - point the admin to the remedy\nif (string.IsNullOrEmpty(_avalaraTaxSettings.CompanyCode) || _avalaraTaxSettings.CompanyCode.Equals(Guid.Empty.ToString()))\n    throw new NopException(\"Company not selected - choose a company in the Avalara provider settings (run 'Get account companies' first)\");","handlingStrategy":"validation","validationCode":"// Guard the export behind a company-selection check\nif (string.IsNullOrEmpty(_avalaraTaxSettings.CompanyCode) ||\n    _avalaraTaxSettings.CompanyCode.Equals(Guid.Empty.ToString()))\n{\n    throw new NopException(\"Select a company before exporting tax codes.\");\n}\nawait taxManager.ExportTaxCodesAsync();","typeGuard":"static bool IsCompanySelected(AvalaraTaxSettings s) =>\n    !string.IsNullOrEmpty(s.CompanyCode) && !s.CompanyCode.Equals(Guid.Empty.ToString());","tryCatchPattern":null,"preventionTips":["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."],"tags":["avalara","company","config"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}