反序列化出错,不知如何解决

eaglet 2004-11-14 04:05:32
[Serializable]
class copy
{
public int a ;
}

copy copyobj1 = new copy ();

IFormatter formatter = new BinaryFormatter ();
Stream stream = new MemoryStream();
formatter.Serialize(stream, copyobj1);
long len = stream.Length ;
copy copyobj2 =(copy)formatter.Deserialize(stream);

stream.Close();


执行到 copy copyobj2 =(copy)formatter.Deserialize(stream); 时出错
错误提示
An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll

Additional information: 在分析完成之前就遇到流结尾。
不知时什么原因

...全文
347 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
eaglet 2004-11-27
  • 打赏
  • 举报
回复
brightheroes 2004-11-14
  • 打赏
  • 举报
回复
stream.Seek(0,SeekOrigin.Begin);//加上这个
copy copyobj2 =(copy)formatter.Deserialize(stream);

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧