[Serializable]
public class GBWP_HEAD
{
public char [] serialNum_;
public cmd cmd_;
public int len_;
public GBWP_HEAD()
{
serialNum_ = new char[20];
} }
[Serializable]
public class GBWP_LOGIN_RESP
{
public GBWP_HEAD head_;
public result result_;
}
GBWP_LOGIN_RESP loginbuf = new GBWP_LOGIN_RESP();
loginbuf.head_ = new GBWP_HEAD();
BinaryFormatter binaryFormatter = new BinaryFormatter();
System.IO.MemoryStream mStm1 = new System.IO.MemoryStream();
binaryFormatter.Serialize(mStm1,loginbuf);
byte[] tmpBytes = mStm1.ToArray();
mStm1.Close();
ns.Write(tmpBytes,0,tmpBytes.Length);//在客户端发送出去。
//服务器端接收反序列化
byte[] buffer = new byte[393];
client.Receive(buffer);
BinaryFormatter binaryFormatter = new BinaryFormatter();
System.IO.MemoryStream mStm2 = new System.IO.MemoryStream(buffer);
mStm2.Position = 0;
object newObj = binaryFormatter.Deserialize(mStm2);//在这里出错
mStm2.Close();
在倒数第二行出错出错信息为:
未处理的“System.Runtime.Serialization.SerializationException”类型的异常出现在 mscorlib.dll 中。其他信息: 无法找到程序集 BlackWhite, Version=1.0.2067.27760, Culture=neutral, PublicKeyToken=null。
小弟菜鸟,还请高人赐教。
搞定了就结贴。

解决方案 »

  1.   

    //服务器端接收反序列化
    byte[] buffer = new byte[393];
    client.Receive(buffer);
    BinaryFormatter binaryFormatter = new BinaryFormatter();
    System.IO.MemoryStream mStm2 = new System.IO.MemoryStream(buffer);
    mStm2.Position = 0;
    object newObj = (类名)binaryFormatter.Deserialize(mStm2);//在这里出错
    mStm2.Close();
      

  2.   

    加上类名也是同样的错误呀。我是在下面这么写的
    GBWP_LOGIN_RESP bbb = (GBWP_LOGIN_RESP)newObj;
      

  3.   

    嗯,这个长度是在客户端用int size = tmpBytes.Length;
    得到的,开始我是写的1024,不好用。我也想可能是长度问题。就用了这个393
      

  4.   

    为什么提示 无法找到程序集 BlackWhite?
    是不是用客户端序列化的东西,不能用其他程序反序列化?