简体   繁体   中英

Serializing an IEnumerable of objects with Newtonsoft in Immediate Window chops the results

We have tried this code that works in the class but fails in the Immediate Window:

System.IO.StreamWriter file = System.IO.File.CreateText("z:\\file.json");
Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer();
serializer.Serialize(file, myCollection);
file.Close();

Even if the Immediate Window returns "Expression has been evaluated and has no value" after each command, the file only has a part of the Json: the file ends abruptly in the middle of a word. Any idea on how to solve this?

As @dbc pointed out in a comment, the problem was a premature file inspection before properly calling

file.Close();

Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM