title: How to serialize object with stream in C#
body: <p>I'm looking for a way to serialize an object with a stream to JSON to POST to an API. I continue to receive this error:</p>
  
  <blockquote>
    <p>Newtonsoft.Json.JsonSerializationException: 'Error getting value from 'ReadTimeout' on 'System.IO.FileStream'.'</p>
  </blockquote>
  
  <p>I understand what the error is saying but I don't understand what I need to implement to resolve it. Does it need to be converted to something else before JSON?</p>
  
  <p>Here is my code:</p>
  
  <p>Model:</p>
  
  <pre><code>[Serializable]
  public class Document
  {
      public string Number { get; set; }
      public string Revision { get; set; }
      public string FileName { get; set; }
      public Stream File { get; set; }
  }
  </code></pre>
  
  <p>Building request:</p>
  
  <pre><code>public Document BuildRequest(string pdfFile, string txtFile)
  {
      Document document = new Document();
  
      try
      {
          string data = File.ReadAllText(txtFile);
          string[] array = data.Split('|');
  
          FileStream fs = new FileStream(pdfFile, FileMode.Open);
  
          document.Number = array[0];
          document.Revision = array[1];
          document.FileName = file;
          document.File = fs;
      }
          // rest of code...
  }
  </code></pre>
  
  <p>Post:</p>
  
  <pre><code>public void Post(Document document)
  {
      var json = JsonConvert.SerializeObject(document);
      // rest of code in method...
  }
  </code></pre>