title: Unable to cast object of type Newtonsoft.Json.Linq.JObject even though I am trying to cast to an object with matching properties
body: <p>I am working with ASP.NET Core 2.0 in VS2017.</p>
  
  <p>I am trying to deserialize some JSON that is returned in an <code>HttpResponseMessage</code> but I am getting an "Unable to cast object of type..." exception.</p>
  
  <p>Here is the code that is failing;</p>
  
  <pre><code>FilesUploadedListResponse fileUploadListResponse = new FilesUploadedListResponse();
  string jsonResult = response.Content.ReadAsStringAsync().Result;
  fileUploadListResponse = (FilesUploadedListResponse)JsonConvert.DeserializeObject(jsonResult);
  </code></pre>
  
  <p>The last line is where I get the exception...</p>
  
  <pre><code>"Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'FilesUploadedListResponse'."
  </code></pre>
  
  <p>Here is the actual Json that is in the string <code>jsonResult</code>:</p>
  
  <pre><code>"{\"uploadedfiles\":[],\"totalResults\":0,\"pageNumber\":0,\"pageSize\":0}"
  </code></pre>
  
  <p>The <code>uploadedFiles</code> array is empty in this result, because there are no uploaded files yet, but I would think that having it empty shouldn't create an exception, should it? If it were not empty, it would have a response similar to this:</p>
  
  <pre><code>{
   "uploadedFiles": [
   {
   "id": 1,
   "createdTime": "July 10, 2017 02:02:25 PM",
   "filename": "20170710_14022507701.jpg",
   "sentTime": "July 10, 2017 02:05:11 PM",
   "fileSize": "124 KB"
   },
   {
   "id": 2,
   "createdTime": "June 05, 2017 09:39:25 AM",
   "filename": "20170605_093907701.jpg",
   "sentTime": "June 05, 2017 09:40:11 AM",
   "fileSize": "1 MB"
   }
  ],
   "totalResults": 2,
   "pageNumber": 0,
   "pageSize": 2
  }
  </code></pre>
  
  <p>Here is my <code>FileUploadListResponse</code> class:</p>
  
  <pre><code>public class FilesUploadedListResponse
  {
      public bool Success { get; set; }
      public string Reason { get; set; }
      public int StatusCode { get; set; }
      public List&lt;UploadedFile&gt; UploadedFiles { get; set; }
      public int TotalResults { get; set; }
      public int PageNumber { get; set; }
      public int PageSize { get; set; }
  }
  </code></pre>
  
  <p>And here is my <code>UploadedFile</code> class:</p>
  
  <pre><code>public class UploadedFile
  {
      public int Id { get; set; }
      public DateTime CreatedTime { get; set; }
      public string Filename { get; set; }
      public DateTime? SentTime { get; set; }
      public string FileSize { get; set; }
  }
  </code></pre>
  
  <p>My understanding of the JSON deserialization is that:</p>
  
  <ol>
  <li><p>The case of the elements doesn't matter between the values in the JSON string and the class object I am trying to deserialize to.</p></li>
  <li><p>The class I am trying to deserialize to can have more properties that what is provided in the JSON string, just as long as the properties that are in the JSON string are accounted for.</p></li>
  <li><p>An empty sub array, such as the <code>UploadedFiles</code> array should not cause an error when trying to deserialize to the <code>List&lt;UploadedFile&gt;</code></p></li>
  </ol>
  
  <p>I am sure it is something simple, but I am just not seeing it. What am I missing here?</p>