Q:

json.net deserialize datestring in IsoFormat

I have this test  case that is failing. Anyone know how to fix it?
    [TestMethod]
    public void Should_deserialize_utc_datestring_to_utc_date_with_AlwaysUseUtc_true()
    {
        string dateString = "2014-06-02T21:00:00.0000000Z";
        DateTime dateRaw = new DateTime(2014, 6, 2, 21, 0, 0, 0, DateTimeKind.Utc);

        JsonSerializerSettings settings = new JsonSerializerSettings();
        settings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
        settings.DateFormatHandling = DateFormatHandling.IsoDateFormat;
        DateTime dateSerialized = JsonConvert.DeserializeObject<DateTime>(dateString, settings);
        dateSerialized.Should().Be(dateRaw);
    }

The error I am getting (using ReSharper as my TestRunner) is:
Test method When_json_serializing_dates.Should_deserialize_utc_datestring_to_utc_date_with_AlwaysUseUtc_true threw exception: 
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing number: T. Path '', line 1, position 10.

A:

The issue is that you are missing embedded quotes around the string (remember, it is expecting JSON). Changing your dateString as follows will resolve your issue:
string dateString = "\"2014-06-02T21:00:00.0000000Z\"";

