title: c# how to deserialize IFormFile
body: <p>I'm sure somebody had the same problem, but I didn't find anything. 
  I send post request to get the file, and I get this model as a response:</p>
  
  <pre><code>    public class ResponseWithFile
  {
      public bool IsSuccessful { get; set; }
      public List&lt;int&gt; Errors { get; set; }
      public IFormFile File { get; set; }
  }
  </code></pre>
  
  <p>I get this response from a controller:</p>
  
  <pre><code>    [Route("get")]
      [HttpPost]
      public async Task&lt;IActionResult&gt; GetFile([FromBody]GetFileDto request)
      {
          var result = _fileService.GetFile(request.Id, request.ContentType);
          if (result.IsSuccessful)
              return Ok(result);
          return BadRequest(result);
      }
  </code></pre>
  
  <p>The response is correct, I can read it into a string, but when I try to deserialize it into response object I get error:</p>
  
  <pre><code>            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
          string respString = string.Empty;
          using (var sr = new StreamReader(resp.GetResponseStream()))
          {
              respString = sr.ReadToEnd();
          }
  
          var serResp = (ResponseWithFile)JsonConvert.DeserializeObject(respString);//error here
  </code></pre>
  
  <blockquote>
    <p>InvalidCastException: Unable to cast object of type &#x27;Newtonsoft.Json.Linq.JObject&#x27; to type &#x27;ServiceModels.ResponseWithFile</p>
  </blockquote>
  
  <p>I'm sure it's because of IFormFile object. What am I doing wrong?</p>