nopSolutions/nopCommerce · error · NopException

Failed to delete customer

Error message

Failed to delete customer

What it means

Thrown when ServiceClient.DeleteCustomerAsync(companyId, customerCode) returns null. Avalara's SDK returns a null result (rather than throwing) when the customer could not be deleted, so the ?? coalesce converts that silent failure into a NopException wrapped by HandleFunctionAsync.

Source

Thrown at src/Plugins/Nop.Plugin.Tax.Avalara/Services/AvalaraTaxManager.cs:1634

    }

    /// <summary>
    /// Delete a customer with the passed identifier
    /// </summary>
    /// <param name="customerId">Customer id</param>
    /// <returns>
    /// A task that represents the asynchronous operation
    /// The task result contains the customer details
    /// </returns>
    public async Task<CustomerModel> DeleteCustomerAsync(int customerId)
    {
        return (await HandleFunctionAsync(async () =>
        {
            if (_avalaraTaxSettings.CompanyId is null)
                throw new NopException("Company not selected");

            return await ServiceClient.DeleteCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customerId.ToString())
                ?? throw new NopException("Failed to delete customer");
        })).Result;
    }

    /// <summary>
    /// Get valid certificates linked to a customer in a particular country and region
    /// </summary>
    /// <param name="customer">Customer</param>
    /// <param name="storeId">Current store id</param>
    /// <returns>
    /// A task that represents the asynchronous operation
    /// The task result contains the list of certificates
    /// </returns>
    public async Task<CertificateModel> GetValidCertificatesAsync(Customer customer, int storeId)
    {
        return (await HandleFunctionAsync(async () =>
        {
            if (_avalaraTaxSettings.CompanyId is null)
                throw new NopException("Company not selected");

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Verify the customerId/customerCode actually exists in Avalara CertCapture for the configured company before attempting deletion.
  2. Inspect the log entry written by HandleFunctionAsync for the underlying Avalara SDK error or HTTP status.
  3. Treat a 'customer not found' case as success (idempotent delete) instead of throwing — verify against ListCustomersAsync first if needed.

Example fix

// before
return await ServiceClient.DeleteCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customerId.ToString())
    ?? throw new NopException("Failed to delete customer");

// after — distinguish missing customer from a real failure
var deleted = await ServiceClient.DeleteCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customerId.ToString());
if (deleted is null)
{
    var existing = await ServiceClient.GetCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customerId.ToString());
    if (existing is null) return null; // already gone — idempotent
    throw new NopException("Failed to delete customer");
}
return deleted;
Defensive patterns

Strategy: try-catch

Validate before calling

var existing = await ServiceClient.GetCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customerId.ToString());
if (existing is null) { /* already absent — treat as deleted */ return; }

Try / catch

try { await _avalaraTaxManager.DeleteCustomerAsync(id); }
catch (NopException ex) when (ex.Message.Contains("Failed to delete customer"))
{ _logger.LogError(ex, "Avalara delete failed for {Id}", id); throw; }

Prevention

When it happens

Trigger: Calling DeleteCustomerAsync for a customerId that does not exist in Avalara CertCapture under the given company; the customer is locked by another transaction; the Avalara service returns an empty/null payload after a 4xx/5xx.

Common situations: Local nopCommerce customer IDs that were never synced to Avalara; stale customerId passed after the customer was already deleted; transient Avalara API outage returning a non-200 with a null deserialized body.

Related errors


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