{"record":{"id":"db1318f979a504d9","repo":"nopSolutions/nopCommerce","slug":"primary-exchange-rate-currency-is-not-set","errorCode":null,"errorMessage":"Primary exchange rate currency is not set","messagePattern":"Primary exchange rate currency is not set","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/Directory/CurrencyService.cs","lineNumber":151,"sourceCode":"    #endregion\r\n\r\n    #region Conversions\r\n\r\n    /// <summary>\r\n    /// Gets live rates regarding the passed currency\r\n    /// </summary>\r\n    /// <param name=\"currencyCode\">Currency code; pass null to use primary exchange rate currency</param>\r\n    /// <returns>\r\n    /// A task that represents the asynchronous operation\r\n    /// The task result contains the exchange rates\r\n    /// </returns>\r\n    public virtual async Task<IList<ExchangeRate>> GetCurrencyLiveRatesAsync(string currencyCode = null)\r\n    {\r\n        var exchangeRateProvider = await _exchangeRatePluginManager.LoadPrimaryPluginAsync()\r\n                                   ?? throw new Exception(\"Active exchange rate provider cannot be loaded\");\r\n\r\n        currencyCode ??= (await GetCurrencyByIdAsync(_currencySettings.PrimaryExchangeRateCurrencyId))?.CurrencyCode\r\n                         ?? throw new NopException(\"Primary exchange rate currency is not set\");\r\n\r\n        return await exchangeRateProvider.GetCurrencyLiveRatesAsync(currencyCode);\r\n    }\r\n\r\n    /// <summary>\r\n    /// Converts currency\r\n    /// </summary>\r\n    /// <param name=\"amount\">Amount</param>\r\n    /// <param name=\"exchangeRate\">Currency exchange rate</param>\r\n    /// <returns>Converted value</returns>\r\n    public virtual decimal ConvertCurrency(decimal amount, decimal exchangeRate)\r\n    {\r\n        if (amount != decimal.Zero && exchangeRate != decimal.Zero)\r\n            return amount * exchangeRate;\r\n\r\n        return decimal.Zero;\r\n    }\r\n\r","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/Directory/CurrencyService.cs#L133-L169","documentation":"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.","triggerScenarios":"Calling GetCurrencyLiveRatesAsync() (no currencyCode) when PrimaryExchangeRateCurrencyId is 0/unset, points to a deleted currency, or the resolved currency has an empty CurrencyCode.","commonSituations":"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.","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."],"exampleFix":"// before\nvar rates = await _currencyService.GetCurrencyLiveRatesAsync();\n\n// after\nif (_currencySettings.PrimaryExchangeRateCurrencyId == 0)\n    throw new InvalidOperationException(\"Configure PrimaryExchangeRateCurrencyId before fetching live rates.\");\nvar rates = await _currencyService.GetCurrencyLiveRatesAsync();","handlingStrategy":"validation","validationCode":"if (_currencySettings.PrimaryExchangeRateCurrencyId == 0)\n    throw new InvalidOperationException(\"Set PrimaryExchangeRateCurrencyId first.\");\nvar rates = await _currencyService.GetCurrencyLiveRatesAsync();","typeGuard":null,"tryCatchPattern":"try { await _currencyService.GetCurrencyLiveRatesAsync(); }\ncatch (NopException ex) when (ex.Message.Contains(\"Primary exchange rate currency is not set\"))\n{ /* prompt admin to configure the primary currency */ }","preventionTips":["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."],"tags":["currency","exchange-rate","configuration","settings"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}