I have a WCF service that returns JSON.
Since this morning, I started to get the following error:
DateTime values that are greater than DateTime.MaxValue or smaller than DateTime.MinValue when converted to UTC cannot be serialized to JSON
Just for the test, I passed today's date to all the DateTime variables that are being returned using JSON, but I stil get the same error.
The code is around 2k rows, so I see no value in posting it here.
Any idea how to solve it??
I suspect you have a DateTime
value that is uninitialized - defaults to DateTime.MinValue
local time. This can not be converted to UTC if your local timezone is ahead of UTC, because doing so would result in a negative Ticks
value.
Either find the uninitialized value and correct it, or move to the USA :)
Another solution might be to use a nullable value (DateTime?
in place of DateTime
).
This defaults to null
rather than DateTime.MinValue
, so you should be able to serialize an uninitialized value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With