0

I try to serialize and deserealize like this:

 var mem = new MemoryStream();
 MessagePackBinary.WriteInt64(mem, 1580358);
 var result = MessagePackBinary.ReadInt64(mem);` 
 //System.InvalidOperationException: 'Invalid MessagePack code was detected, code:-1'

But i have error. What i do wrong? Thank you!

Using library: MessagePack repo

Admiral Land
  • 2,304
  • 7
  • 43
  • 81

1 Answers1

3

You should rewind the stream to initial position to read back what you wrote there:

var mem = new MemoryStream();
MessagePackBinary.WriteInt64(mem, 1580358);
mem.Seek(0, SeekOrigin.Begin); // added
var result = MessagePackBinary.ReadInt64(mem);
Console.WriteLine(result);
Peter Wolf
  • 3,700
  • 1
  • 15
  • 30