title: Json.Net fails to serialize to a stream, but works just fine serializing to a string
body: <p>Internally, <code>JsonConvert.SerializeObject(obj, Formatting.Indented)</code> boils down to</p>
  
  <pre><code>JsonSerializer jsonSerializer = JsonSerializer.Create(null);
  StringWriter stringWriter = new StringWriter(new StringBuilder(256), (IFormatProvider) CultureInfo.InvariantCulture);
  using (JsonTextWriter jsonTextWriter = new JsonTextWriter((TextWriter) stringWriter))
  {
    jsonTextWriter.Formatting = formatting;
    jsonSerializer.Serialize((JsonWriter) jsonTextWriter, value);
  }
  return stringWriter.ToString();
  </code></pre>
  
  <p>This works just fine. However, if I do the following:</p>
  
  <pre><code>string json;
  
  JsonSerializer jsonSerializer = JsonSerializer.Create();
  
  using (var stream = new MemoryStream())
  using (var streamWriter = new StreamWriter(stream, Encoding.UTF8))
  using (var jsonWriter = new JsonTextWriter(streamWriter))
  {
      serializer.Serialize(jsonWriter, cmd);
  
      stream.Position = 0;
      using (var reader = new StreamReader(stream))
      {
          json = reader.ReadToEnd();
      }
  }
  </code></pre>
  
  <p>Then the value of <code>json</code> is <code>""</code>. Can anyone point me to my mistake?</p>