2011-01-19 77 views
1

什么是异常“分析完成前遇到的流结束”。在我的代码?序列化异常

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

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

您需要更好的变量名称。 – SLaks 2011-01-19 15:37:45

回答

3

序列化对象到流后,该流的Position是在末端。
因此,解串器无法读取数据流。

您需要倒带流,设置为n.Position = 0

+0

感谢您的帮助。 – 2011-01-19 15:39:01