'Unexpected token readed 'EndOfStream' while 'BeginObject' is expected.' ?
Orhonbey opened this issue · comments
Hi
I am use your library first time
but I get this error.
Can you help me ?
Thank you.
'Unexpected token readed 'EndOfStream' while 'BeginObject' is expected.'
private T ByteConverter<T>(byte[] value) { var stream = new MemoryStream(); stream.Write(value, 0, value.Length); T result = (T)MsgPack.Deserialize(typeof(T), stream); return result; }
Hi @sunal. You need to rewind back stream after Write().
stream.Position = 0;
and better to use special non-copying constructor of MemoryStream:
var stream = new MemoryStream(value, 0, value.Length, writable: false);
// no rewind required
Does T
and all deserialized types has parameter-less constructor defined?
Example:
class MyClass
{
public MyClass() { /* this is parameter-less constructor */ }
}
This is required for deserialization. Because deserializer need to create instances of your types.
Thank you my problem solved .