流的末尾遇到解析完成之前? [英] End of Stream encountered before parsing was completed?

查看:799
本文介绍了流的末尾遇到解析完成之前?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想反序列化一个流,但我总​​是得到这个错误流的末尾遇到过分析完成?

I am trying to deserialize a stream but I always get this error "End of Stream encountered before parsing was completed"?

下面是code:

        //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

任何一个有想法?

Any one have ideas?

推荐答案

尝试将位置设置为0的数据流,并且不使用你的对象,但对象类型。

Try to set the position to 0 of your stream and do not use your object but the object type.

        BinaryFormatter b = new BinaryFormatter();
        s.Position = 0;
        return (YourObjectType)b.Deserialize(s);

这篇关于流的末尾遇到解析完成之前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆