2011-01-19 106 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