nopSolutions/nopCommerce · error · NopException
Exchange rate not found for currency [{targetCurrencyCode.Na
Error message
Exchange rate not found for currency [{targetCurrencyCode.Name}] What it means
Thrown by ConvertFromPrimaryExchangeRateCurrencyAsync as a NopException when targetCurrencyCode.Rate equals decimal.Zero. The conversion multiplies by the target's Rate; a zero rate silently zeroes out the converted amount, so the guard rejects it. Mirror of error 36 for the reverse direction.
Source
Thrown at src/Libraries/Nop.Services/Directory/CurrencyService.cs:280
/// <param name="amount">Amount</param>
/// <param name="targetCurrencyCode">Target currency code</param>
/// <returns>
/// A task that represents the asynchronous operation
/// The task result contains the converted value
/// </returns>
public virtual async Task<decimal> ConvertFromPrimaryExchangeRateCurrencyAsync(decimal amount, Currency targetCurrencyCode)
{
ArgumentNullException.ThrowIfNull(targetCurrencyCode);
var primaryExchangeRateCurrency = await GetCurrencyByIdAsync(_currencySettings.PrimaryExchangeRateCurrencyId) ?? throw new Exception("Primary exchange rate currency cannot be loaded");
var result = amount;
if (result == decimal.Zero || targetCurrencyCode.Id == primaryExchangeRateCurrency.Id)
return result;
var exchangeRate = targetCurrencyCode.Rate;
if (exchangeRate == decimal.Zero)
throw new NopException($"Exchange rate not found for currency [{targetCurrencyCode.Name}]");
result *= exchangeRate;
return result;
}
#endregion
#endregion
}View on GitHub (pinned to 64bdf2ff08)
Solutions
- Set a non-zero Rate for the target currency in Admin > Configuration > Currencies.
- Guard: validate targetCurrency.Rate > 0 before converting.
- Run a live-rate refresh to repopulate rates.
Example fix
// before
var value = await _currencyService.ConvertFromPrimaryExchangeRateCurrencyAsync(amount, targetCurrency);
// after
if (targetCurrency.Rate == decimal.Zero)
throw new InvalidOperationException($"Currency '{targetCurrency.Name}' has no exchange rate set.");
var value = await _currencyService.ConvertFromPrimaryExchangeRateCurrencyAsync(amount, targetCurrency); Defensive patterns
Strategy: validation
Validate before calling
if (targetCurrency.Rate == decimal.Zero)
throw new InvalidOperationException($"Currency '{targetCurrency.Name}' has no rate."); Type guard
static bool HasRate(Currency c) => c is not null && c.Rate != decimal.Zero;
Try / catch
try { await _currencyService.ConvertFromPrimaryExchangeRateCurrencyAsync(amount, tgt); }
catch (NopException ex) when (ex.Message.Contains("Exchange rate not found"))
{ _logger.LogWarning(ex, "Missing rate; skipping conversion."); } Prevention
- Set a non-zero Rate for every dimension's currency counterpart.
- Refresh live rates periodically.
- Validate Rate > 0 before converting.
When it happens
Trigger: Calling ConvertFromPrimaryExchangeRateCurrencyAsync with a target Currency whose Rate is 0. Triggers only when target differs from the primary currency and amount is non-zero.
Common situations: Target currency added without a rate; rate cleared/reset by admin; import with Rate=0.
Related errors
- Exchange rate not found for currency [{sourceCurrencyCode.Na
- Active exchange rate provider cannot be loaded
- Primary exchange rate currency is not set
- Primary exchange rate currency cannot be loaded
- Exchange ratio not set for dimension [{targetMeasureDimensio
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/be9bfbaca8279b88.
Report an issue: GitHub.