End of Stream encountered before parsing was completed?

橙三吉。 提交于 2019-11-29 00:54:52

Try to set the position to 0 of your stream and do not use your object but the object type.

        BinaryFormatter b = new BinaryFormatter();
        s.Position = 0;
        return (YourObjectType)b.Deserialize(s);

Make sure the serialization completed, and that the serialization type matches the de-serialization type (i.e., make sure you're serializing with a BinaryFormatter if you're de-serializing with one). Also, make sure that the stream you serialized to really finished serializing, with a Stream.Flush() or something to that effect.

I had the same exception thrown, until I added the [Serializable] tag to the class I was Serializing :)

Then it all worked perfectly.

chandpriyankara
s.Position = 0;

this is because you have to go to the start back to start copying data on the array!

Alia Ramli Ramli

In my case I used:

stream.Seek(0, SeekOrigin.Begin);

after i serialized the stream, and before i deserialized the stream works charm. hope this helps!

I just encountered a similar error

It was about getting a different data type when serializing and deserializing. By mistake, when storing the data to mariadb I used MediumText and when getting the data I used Text this is why I got only part of the stream.

Just check if the data types are the same.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!