{"record":{"id":"be9bfbaca8279b88","repo":"nopSolutions/nopCommerce","slug":"exchange-rate-not-found-for-currency-targetcurre","errorCode":null,"errorMessage":"Exchange rate not found for currency [{targetCurrencyCode.Name}]","messagePattern":"Exchange rate not found for currency \\[(.+?)\\]","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/Directory/CurrencyService.cs","lineNumber":280,"sourceCode":"    /// <param name=\"amount\">Amount</param>\r\n    /// <param name=\"targetCurrencyCode\">Target currency code</param>\r\n    /// <returns>\r\n    /// A task that represents the asynchronous operation\r\n    /// The task result contains the converted value\r\n    /// </returns>\r\n    public virtual async Task<decimal> ConvertFromPrimaryExchangeRateCurrencyAsync(decimal amount, Currency targetCurrencyCode)\r\n    {\r\n        ArgumentNullException.ThrowIfNull(targetCurrencyCode);\r\n\r\n        var primaryExchangeRateCurrency = await GetCurrencyByIdAsync(_currencySettings.PrimaryExchangeRateCurrencyId) ?? throw new Exception(\"Primary exchange rate currency cannot be loaded\");\r\n\r\n        var result = amount;\r\n        if (result == decimal.Zero || targetCurrencyCode.Id == primaryExchangeRateCurrency.Id)\r\n            return result;\r\n\r\n        var exchangeRate = targetCurrencyCode.Rate;\r\n        if (exchangeRate == decimal.Zero)\r\n            throw new NopException($\"Exchange rate not found for currency [{targetCurrencyCode.Name}]\");\r\n        result *= exchangeRate;\r\n\r\n        return result;\r\n    }\r\n\r\n    #endregion\r\n\r\n    #endregion\r\n}","sourceCodeStart":262,"sourceCodeEnd":289,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/Directory/CurrencyService.cs#L262-L289","documentation":"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.","triggerScenarios":"Calling ConvertFromPrimaryExchangeRateCurrencyAsync with a target Currency whose Rate is 0. Triggers only when target differs from the primary currency and amount is non-zero.","commonSituations":"Target currency added without a rate; rate cleared/reset by admin; import with Rate=0.","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."],"exampleFix":"// before\nvar value = await _currencyService.ConvertFromPrimaryExchangeRateCurrencyAsync(amount, targetCurrency);\n\n// after\nif (targetCurrency.Rate == decimal.Zero)\n    throw new InvalidOperationException($\"Currency '{targetCurrency.Name}' has no exchange rate set.\");\nvar value = await _currencyService.ConvertFromPrimaryExchangeRateCurrencyAsync(amount, targetCurrency);","handlingStrategy":"validation","validationCode":"if (targetCurrency.Rate == decimal.Zero)\n    throw new InvalidOperationException($\"Currency '{targetCurrency.Name}' has no rate.\");","typeGuard":"static bool HasRate(Currency c) => c is not null && c.Rate != decimal.Zero;","tryCatchPattern":"try { await _currencyService.ConvertFromPrimaryExchangeRateCurrencyAsync(amount, tgt); }\ncatch (NopException ex) when (ex.Message.Contains(\"Exchange rate not found\"))\n{ _logger.LogWarning(ex, \"Missing rate; skipping conversion.\"); }","preventionTips":["Set a non-zero Rate for every dimension's currency counterpart.","Refresh live rates periodically.","Validate Rate > 0 before converting."],"tags":["currency","exchange-rate","data","configuration"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}