Freigeben über


JSON Serialization in WCF and .NET 3.5

I just burned an hour chasing down a JSON serialization issue in .NET 3.5.  Watch out for trying to serialize DateTime values that are MaxValue or MinValue.  This is an issue whether you are using the DataContractJsonSerializer directly or if you are using a WebInvoke with response formatting set to Json.  The latter can be much trickier to detect.

The following line of code was my problem:

        // This will hose you in when using WCF's DataContractJsonSerializer
        flight.ActualArrivalTime = DateTime.MaxValue;

 I stepped through to find this dialog below.  

JSONError

 After removing MaxValue, it worked fine.

Comments