Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

InvalidCastException when reading Int128/UInt128 #3009

Open
DmitryJacobs opened this issue Jan 12, 2025 · 0 comments
Open

InvalidCastException when reading Int128/UInt128 #3009

DmitryJacobs opened this issue Jan 12, 2025 · 0 comments

Comments

@DmitryJacobs
Copy link

DmitryJacobs commented Jan 12, 2025

Source/destination types

class Test
{
    [JsonProperty("value")]
    public System.Int128 Value { get; set; }
}

Source/destination JSON

{"value":1329227995784915872903807060280344575}

Actual behavior

Newtonsoft.Json.JsonSerializationException: 'Error converting value 1329227995784915872903807060280344575 to type 'System.Int128'. Path 'value', line 1, position 46.'
Inner Exception:
ArgumentException: Could not cast or convert from System.Numerics.BigInteger to System.Int128.

Steps to reproduce

JsonConvert.DeserializeObject<Test>("{\"value\":1329227995784915872903807060280344575}");

If I use a type of JSON token that is a string, it works correctly. That is, like this:

JsonConvert.DeserializeObject<Test>("{\"value\":\"1329227995784915872903807060280344575\"}");
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant