title: Newtonsoft JSON - Dynamic Objects
body: <p>I am using the Newtonsoft JSON library to perform dynamic deserialisation on incoming raw JSON and have found something that I just can't explain.</p>
  
  <p>The starting point is the following JSON string:</p>
  
  <pre><code>{
    "task": {
      "dueDate": "2012-12-03T00:00:00"
    }
  }
  </code></pre>
  
  <p>Nothing too complex there...</p>
  
  <p>In code I am then doing this:</p>
  
  <pre><code>var dyn = JsonConvert.DeserializeObject&lt;dynamic&gt;(rawJson);
  DateTime dueDate = dyn.task.dueDate.Value;
  </code></pre>
  
  <p>This code has been in place for months and works fine, however in a recent test build we were seeing the following error:</p>
  
  <blockquote>
    <p>'Newtonsoft.Json.Linq.JObject' does not contain a definition for
    'task' </p>
    
    <p>Stack Trace:   at CallSite.Target(Closure , CallSite , Object )     at
    System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite
    site, T0 arg0)</p>
  </blockquote>
  
  <p>Now this is where is gets odd, everything starts to work again if I change the code above from:</p>
  
  <pre><code>DateTime dueDate = dyn.task.dueDate.Value;
  </code></pre>
  
  <p>to</p>
  
  <pre><code>DateTime dueDate = dyn["task"]["dueDate"].Value;
  </code></pre>
  
  <p>So, although this is "fixed" I don't understand why this fixes it and what the possible cause could be.  Does anybody have any ideas</p>