Binary stream '0' does not contain a valid BinaryHeader. Occurs randomly

倾然丶 夕夏残阳落幕 提交于 2019-12-01 21:09:45

If you are using above deserializing methods & also call them while getting stream from clientstream OR other streams.... skip it. try to use directly those streams with formatter. Like Below :

NetworkStream clientStream = client.GetStream();
Object src = (Object)formatter.Deserialize(clientStream);

I have found the bug. The code above works fine, but care for encoding in some cases(!), so feel free to use it. The problem laying in another part of a program, where I mistyped and send 4 bytes BUT the client app was told to receive 8, so in most cases it filled it in with zeros, but sometimes it got it from next pack of data.

It was @Marc Gravell and his blog that made me look over and over again to eventually find the source.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!