日期:2014-05-18  浏览次数:20901 次

byte数组反序列化的问题???
string StrCartNew = Server.UrlDecode(Request.Cookies[CookieName].Value.ToString()); 
byte[] bt = System.Text.Encoding.Default.GetBytes(StrCartNew); 
Stream smNew = new MemoryStream(bt); 
IFormatter fmNew = new BinaryFormatter(); 
ShopCart SCNew = (ShopCart)fmNew.Deserialize(smNew); 
foreach(ShopCartItem SCI in SCNew.CartItems) 

lblResult.Text += "<br/>产品名称:" + SCI.Name; 

这个我在运行的时候出错。这个错误: 
BinaryFormatter Version incompatibility. Expected Version 1.0. Received Version 623915045.807743536. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Runtime.Serialization.SerializationException: BinaryFormatter Version incompatibility. Expected Version 1.0. Received Version 623915045.807743536. 
这行代码有问题 ShopCart SCNew = (ShopCart)fmNew.Deserialize(smNew); 
不知道为什么。

------解决方案--------------------
你把一串字符串存成byte数组,然后再用它反序列化成ShopCart对象。那个字符串数据估计有问题,不能反序列化成目标对象。你当初是怎么保存的呢?