nopSolutions/nopCommerce · error · NopException
Primary exchange rate currency is not set
Error message
Primary exchange rate currency is not set
What it means
Thrown by GetCurrencyLiveRatesAsync as a NopException when currencyCode is null and the primary exchange-rate currency (CurrencySettings.PrimaryExchangeRateCurrencyId) resolves to null or has no CurrencyCode. The primary exchange-rate currency is the base currency for live rate fetching and must be configured.
Source
Thrown at src/Libraries/Nop.Services/Directory/CurrencyService.cs:151
#endregion
#region Conversions
/// <summary>
/// Gets live rates regarding the passed currency
/// </summary>
/// <param name="currencyCode">Currency code; pass null to use primary exchange rate currency</param>
/// <returns>
/// A task that represents the asynchronous operation
/// The task result contains the exchange rates
/// </returns>
public virtual async Task<IList<ExchangeRate>> GetCurrencyLiveRatesAsync(string currencyCode = null)
{
var exchangeRateProvider = await _exchangeRatePluginManager.LoadPrimaryPluginAsync()
?? throw new Exception("Active exchange rate provider cannot be loaded");
currencyCode ??= (await GetCurrencyByIdAsync(_currencySettings.PrimaryExchangeRateCurrencyId))?.CurrencyCode
?? throw new NopException("Primary exchange rate currency is not set");
return await exchangeRateProvider.GetCurrencyLiveRatesAsync(currencyCode);
}
/// <summary>
/// Converts currency
/// </summary>
/// <param name="amount">Amount</param>
/// <param name="exchangeRate">Currency exchange rate</param>
/// <returns>Converted value</returns>
public virtual decimal ConvertCurrency(decimal amount, decimal exchangeRate)
{
if (amount != decimal.Zero && exchangeRate != decimal.Zero)
return amount * exchangeRate;
return decimal.Zero;
}
View on GitHub (pinned to 64bdf2ff08)
Solutions
- Set the 'Primary exchange rate currency' in Admin > Configuration > Currencies to a valid, active currency with a code (e.g., USD, EUR).
- Ensure CurrencySettings.PrimaryExchangeRateCurrencyId points to an existing Currency row with a non-empty CurrencyCode.
- Pass currencyCode explicitly to GetCurrencyLiveRatesAsync(code) to bypass the null path when the setting is intentionally unset.
Example fix
// before
var rates = await _currencyService.GetCurrencyLiveRatesAsync();
// after
if (_currencySettings.PrimaryExchangeRateCurrencyId == 0)
throw new InvalidOperationException("Configure PrimaryExchangeRateCurrencyId before fetching live rates.");
var rates = await _currencyService.GetCurrencyLiveRatesAsync(); Defensive patterns
Strategy: validation
Validate before calling
if (_currencySettings.PrimaryExchangeRateCurrencyId == 0)
throw new InvalidOperationException("Set PrimaryExchangeRateCurrencyId first.");
var rates = await _currencyService.GetCurrencyLiveRatesAsync(); Try / catch
try { await _currencyService.GetCurrencyLiveRatesAsync(); }
catch (NopException ex) when (ex.Message.Contains("Primary exchange rate currency is not set"))
{ /* prompt admin to configure the primary currency */ } Prevention
- Configure the primary exchange-rate currency during store setup.
- Pass an explicit currencyCode when the setting is intentionally unset.
- Add a startup check that the setting is non-zero.
When it happens
Trigger: Calling GetCurrencyLiveRatesAsync() (no currencyCode) when PrimaryExchangeRateCurrencyId is 0/unset, points to a deleted currency, or the resolved currency has an empty CurrencyCode.
Common situations: Fresh install where the primary exchange-rate currency hasn't been set in Admin > Configuration > Currencies; a currency referenced by the setting was later deleted; partial migration of settings.
Related errors
- Primary exchange rate currency cannot be loaded
- Active exchange rate provider cannot be loaded
- Exchange rate not found for currency [{sourceCurrencyCode.Na
- Exchange rate not found for currency [{targetCurrencyCode.Na
- Usernames are disabled
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/db1318f979a504d9.
Report an issue: GitHub.