序列化异常

时间:2011-01-19 15:33:40

标签: binaryformatter

什么是异常“在解析完成之前遇到的流结束。”在我的代码中?

BinaryFormatter t = new BinaryFormatter();
MemoryStream n = new MemoryStream();
t.Serialize(n, j);

BinaryFormatter q = new BinaryFormatter();
MemoryStream x = new MemoryStream();
q.Deserialize(n);

1 个答案:

答案 0 :(得分:3)

将对象序列化到流后,流的Position就在最后 因此,流中没有更多内容可供解串器读取。

您需要设置n.Position = 0

来回放信息流