Mis*_*Dev 43 .net c# serialization .net-2.0 c#-2.0
我试图反序列化一个流,但我总是得到这个错误"在解析完成之前遇到的流结束"?
这是代码:
        //Some code here
        BinaryFormatter b = new BinaryFormatter();
        return (myObject)b.Deserialize(s);//s---> is a Stream object that has been fill up with data some line over here
有谁有想法?
Pat*_*ins 53
尝试将流的位置设置为0,不要使用对象,而是使用对象类型.
        BinaryFormatter b = new BinaryFormatter();
        s.Position = 0;
        return (YourObjectType)b.Deserialize(s);
确保序列化已完成,并且序列化类型与反序列化类型匹配(即,如果您使用二进制格式化序列化,请确保使用BinaryFormatter进行序列化).此外,请确保您序列化的流完全序列化,使用Stream.Flush()或其他类似的效果.
| 归档时间: | 
 | 
| 查看次数: | 42473 次 | 
| 最近记录: |