5

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??

1
  • You might want to edit in some sample code, and maybe the culture you're currently working in (could be that the date is formatted incorrectly). Commented Oct 11, 2012 at 12:52

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.