nopSolutions/nopCommerce · error · NopException

LicenseKey is not set

Error message

LicenseKey is not set

What it means

Thrown by PrepareSecurity() in ItemClassificationHttpClient when _avalaraTaxSettings.LicenseKey is null. The license key is the secret half of the Basic-auth credential pair; without it the HS classification API call cannot be authenticated.

Source

Thrown at src/Plugins/Nop.Plugin.Tax.Avalara/Services/ItemClassificationHttpClient.cs:52

        _avalaraTaxSettings = avalaraTaxSettings;
        _httpClient = httpClient;
    }

    #endregion

    #region Utilities

    /// <summary>
    /// Set security using CompanyId / License Key
    /// </summary>
    /// <returns>Security token</returns>
    protected string PrepareSecurity()
    {
        if (_avalaraTaxSettings.AccountId is null)
            throw new NopException("AccountId not set");

        if (_avalaraTaxSettings.LicenseKey is null)
            throw new NopException("LicenseKey is not set");

        var s = $"{_avalaraTaxSettings.AccountId}:{_avalaraTaxSettings.LicenseKey}";
        return Convert.ToBase64String(Encoding.UTF8.GetBytes(s));
    }

    #endregion

    #region Methods

    /// <summary>
    /// Request services
    /// </summary>
    /// <typeparam name="TRequest">Request type</typeparam>
    /// <typeparam name="TResponse">Response type</typeparam>
    /// <param name="request">Request</param>
    /// <returns>The asynchronous task whose result contains response details</returns>
    public async Task<TResponse> RequestAsync<TRequest, TResponse>(TRequest request) where TRequest : Request where TResponse : Response
    {

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Enter the Avalara LicenseKey (from Avalara account settings > Security) on the plugin configuration page.
  2. Confirm the key was not truncated or whitespace-trimmed on save.
  3. After rotation in Avalara, update the stored key in nopCommerce immediately.

Example fix

// before
if (_avalaraTaxSettings.LicenseKey is null)
    throw new NopException("LicenseKey is not set");

// after — validate pair together at save time
if (string.IsNullOrWhiteSpace(model.LicenseKey))
    ModelState.AddModelError(nameof(model.LicenseKey), "LicenseKey is required for HS classification");
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(_avalaraTaxSettings.LicenseKey))
    throw new InvalidOperationException("Avalara LicenseKey is required for HS classification");

Type guard

static bool HasLicenseKey(AvalaraTaxSettings s) => !string.IsNullOrWhiteSpace(s?.LicenseKey);

Try / catch

try { await client.RequestAsync<...,...>(req); }
catch (NopException ex) when (ex.Message == "LicenseKey is not set")
{ _notificationService.ErrorNotification("Enter your Avalara LicenseKey."); }

Prevention

When it happens

Trigger: HS classification request runs (RequestAsync) while the Avalara LicenseKey is missing from the plugin configuration.

Common situations: LicenseKey cleared/rotated but not re-entered; admin saved only AccountId; secret redacted during settings export/import.

Related errors


AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13). Data as JSON: /api/errors/11267e2c9ace8a08. Report an issue: GitHub.