From c8d2b4f09db1aa471df873a9f01bb4a53040f729 Mon Sep 17 00:00:00 2001 From: Jkorf Date: Wed, 11 Feb 2026 12:57:03 +0100 Subject: [PATCH] Added check EnumConverter to detect undefined int value parsing --- .../Converters/SystemTextJson/EnumConverter.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CryptoExchange.Net/Converters/SystemTextJson/EnumConverter.cs b/CryptoExchange.Net/Converters/SystemTextJson/EnumConverter.cs index 4f733ba..757af9f 100644 --- a/CryptoExchange.Net/Converters/SystemTextJson/EnumConverter.cs +++ b/CryptoExchange.Net/Converters/SystemTextJson/EnumConverter.cs @@ -168,7 +168,7 @@ namespace CryptoExchange.Net.Converters.SystemTextJson if (!_unknownValuesWarned.Contains(stringValue)) { _unknownValuesWarned.Add(stringValue!); - LibraryHelpers.StaticLogger?.LogWarning($"Cannot map enum value. EnumType: {enumType.FullName}, Value: {stringValue}, Known values: {string.Join(", ", _mappingToEnum!.Select(m => m.Value))}. If you think {stringValue} should added please open an issue on the Github repo"); + LibraryHelpers.StaticLogger?.LogWarning($"Cannot map enum value. EnumType: {enumType.FullName}, Value: {stringValue}, Known values: [{string.Join(", ", _mappingToEnum!.Select(m => $"{m.StringValue}: {m.Value}"))}]. If you think {stringValue} should added please open an issue on the Github repo"); } } @@ -246,6 +246,12 @@ namespace CryptoExchange.Net.Converters.SystemTextJson { // If no explicit mapping is found try to parse string result = (T)Enum.Parse(objectType, value, true); + if (!Enum.IsDefined(objectType, result)) + { + result = default; + return false; + } + return true; } catch (Exception)