开发者

Binary stream 'NN' does not contain a valid BinaryHeader

I am passing user defined classes over sockets. The SendObject code is below. It works on my local machine, but when 开发者_高级运维I publish to the WebServer which is then communicating with the App Server on my own machine it fails.

    public bool SendObject(Object obj, ref string sErrMsg)
    {
        try
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf1 = new BinaryFormatter();
            bf1.Serialize(ms, obj);
            byte[] byArr = ms.ToArray();
            int len = byArr.Length;
            m_socClient.Send(byArr);
            return true;
        }
        catch (Exception e)
        {
            sErrMsg = "SendObject Error: " + e.Message;
            return false;
        }
    }

I can do this fine if it is one class in my tools project and the other class about UserData just doesn't want to know. Frustrating!

Ohh. I think it's because the UserData class has a DataSet inside it. Funnily enough I have seen this work, but then after 1 request it goes loopy and I can't get it to work again.

Anyone know why this might be? I have looked at comparing the dlls to make sure they are the same on the WebServer and on my local machine and they look to be so as I have turned on versioning in the AssemblyInfo.cs to double check.

Possible causes are invalid stream or object version change between serialization and deserialization.


Edit:

Ok it seems that the problem is with size. If I keep it under 1024 byes ( I am guessing here) it works on the web server and doesn't if it has a DataSet inside it.k In fact this is so puzzling I converted the DataSet to a string using ds.GetXml() and this also causes it to blow up. :( So it seems that across the network something with my sockets is wrong and doesn't want to read in the data.


This is solved by a better question I have posted here :

Sending large serialized objects over sockets is failing only when trying to grow the byte Array, but ok when using a massive byte array

Obviously I had a static buffer that I had lifted from some toy example, and then when I started passing populated datasets they were too large. The answers to some dynamic buffer problems I was having cover this too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜