WCF error when converting datetime format to json

I have a WCF service that returns JSON.

From this morning, I started getting 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 the date today to all DateTime variables returned with JSON, but I get the same error.

The code is about 2 thousand lines, so I do not see the value when placing it here.

Any idea how to solve it?

+4
source share
1 answer

I suspect you have a DateTime value that is not initialized - the default is DateTime.MinValue local time. This cannot be converted to UTC if your time zone exceeds UTC because it will result in a negative Ticks value.

Either find the uninitialized value and correct it, or go to the USA :)

Another solution might be to use a value with a null value ( DateTime? Instead of DateTime ).

The default is null , not DateTime.MinValue , so you can serialize an uninitialized value.

+4
source

Source: https://habr.com/ru/post/1439155/


All Articles