2

The Input and output streams section of the Microsoft Bond documentation provides this sample code to deserialize from a file:

using (var stream = new FileStream("example.bin", FileMode.Open))
{
    var input = new InputStream(stream);
    var reader = new CompactBinaryReader<InputStream>(input);
    var example = Deserialize<Example>.From(reader);
}

I tried the reverse to serialize to file, but nothing is written to the file.

using (var stream = new FileStream("example.bin", FileMode.Create))
{
    var output = new OutputStream(stream);
    var writer = new CompactBinaryWriter<OutputStream>(output);  
    Serialize.To(writer, example);
}

Any ideas?

Justin Lilly
  • 147
  • 1
  • 9

1 Answers1

4

It looks like the OutputStream hasn't been flushed into the FileStream. Try adding an explicit call to OutputStream.Flush like the stream example does:

using (var stream = new FileStream("example.bin", FileMode.Create))
{
    var output = new OutputStream(stream);
    var writer = new CompactBinaryWriter<OutputStream>(output);  
    Serialize.To(writer, example);
    output.Flush();
}

I was not around when OutputStream was designed, so I cannot comment on the decision process that resulted in it not implementing IDisposable.

chwarr
  • 6,777
  • 1
  • 30
  • 57