You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exception "input string was not in the correct format"
Steps to reproduce
Theclient call "decimal d = j.Value<decimal>("dataKey");" ends up in Extensions.cs / internal static U? Convert<T, U>(this T token) where T : JToken? { ... } / line 297 "return (U?)System.Convert.ChangeType(value.Value, targetType, CultureInfo.InvariantCulture);"
This call is fine when the U type is Double as in that case System.Convert.ChangeType(...) calls System.Convert.ToDouble(string, CultureType) which calls Double.Parse(s, NumberStyles.Float | NumberStyles.AllowThousand, ...)
Note that NumberStyles.Float includes NumberStyles.AllowExponent.
However when the U type is Decimal, System.Convert.ChangeType(...) calls System.Convert.ToDecimal(string, CultureType) which calls Decimal.Parse(s, NumberStyles.Number, ...) which does NOT have the NumberStyle.AllowExponent.
My suggestion is to handle the case of U being Decimal and value.Value being String separately from the generic return:if((targetType==typeof(decimal))&&(value.Value !=null)&&(value.Value.GetType()==typeof(string)))
return (U?)System.Convert.ChangeType(decimal.Parse(value.Value asstring, NumberStyles.Number | NumberStyles.AllowExponent, CultureInfo.InvariantCulture), targetType, CultureInfo.InvariantCulture);elsereturn(U?)System.Convert.ChangeType(value.Value, targetType, CultureInfo.InvariantCulture);
The text was updated successfully, but these errors were encountered:
Source/destination types
Source/destination JSON
Expected behavior
d = 0.0005445
Actual behavior
Exception "input string was not in the correct format"
Steps to reproduce
The text was updated successfully, but these errors were encountered: