二进制格式化程序异常
我正在尝试将对象图从服务器进程移动到客户端。它有效。至少当客户端和服务器都在我的开发虚拟机上时它可以工作。当我在我的基础机器上运行服务器(开发虚拟机上的客户端)时,它也可以工作。
但当我在媒体中心电脑上运行服务器时,它停止工作。例外的是:
二进制流“0”不包含有效的 BinaryHeader。可能的原因是序列化和反序列化之间无效的流或对象版本更改。
所有三台 PC 均为 x64 Windows 7 计算机。我使用 TCPClient 和 TCPListener 以及 BinaryFormatter 类来完成繁重的工作。
使用标准 FileStream
对象从文件中读取正在传输的数据。
如果在客户端我将缓冲区序列化到文件中,则内容(根据 BeyondCompare)实际上似乎有所不同?!?
我的对象上的所有字符串属性均在 setter 中进行 Base64 编码,并在 getter 中进行解码。
我可以发布代码,但我不确定问题所在?有什么想法吗?
I'm attempting to move an object graph from a server process to a client. And it works. At least it works when the both the client and server are on my dev virtual machine. It also works when I run the server on my base machine (client on dev vm).
It stops working though, when I run the server on my media centre PC. The exception is:
Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization.
All three PC's are x64 Windows 7 machines. I'm using TCPClient and TCPListener along with the BinaryFormatter
class to do the heavy lifting.
The data being transferred is read from a file using a standard FileStream
object.
If at the client end I serialize the buffers to a file, the contents (according to BeyondCompare) do actually seem to differ?!?
All string properties on my objects are Base64 encoded in the setters and decoded in the getters.
I can post code but I'm not sure where the problem area lies? Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:我似乎已经解决了这个问题。我有一个断点,客户端读取服务器响应
并注意到从“问题”服务器读取的字节较少。经过快速谷歌后,我发现这篇文章 http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/759f3f2f-347b-4bd8-aa05-fb7f681c3426 其中 Dave Murray 建议:
因此,我将我的代码从一次读取更新为:
并更新了我的服务器代码以按照帖子关闭连接。根据 @leppie 的评论,我可能可以删除我的 Base64 包装属性......
Update: I've seemingly solved this issue. I had a breakpoint where the client read the server response
and noted that fewer bytes were read from the "problem" server. After a quick google I found this article http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/759f3f2f-347b-4bd8-aa05-fb7f681c3426 in which Dave Murray suggests:
So i updated my code from a single read to:
and updated my server code to close the connection as per the post. And according to the comment from @leppie i can probably remove my Base64 wrapped properties...