[ProtoContract]
public class LoginMsg : MsgBase
{
    [ProtoMember(1)]
    public string User { get; set; }
    [ProtoMember(2)]
    public string Pwd { get; set; }
    [ProtoMember(3)]
    public override ProtoCode Proto { get; set; }
    public LoginMsg()
    {
        Proto = ProtoCode.LoginMsg;
    }
}
 public void SendData(MsgBase msg)
    {
        try
        {
            byte[] sendArr = PackData(msg);
            ByteArray ba = new ByteArray(sendArr);
            int count = 0;
            lock (que_Write)
            {
                que_Write.Enqueue(ba);
                count = que_Write.Count;
            }
            if (count == 1)
            {
                m_Socket.BeginSend(sendArr, 0, sendArr.Length, 0, SendCallBack, m_Socket);
            }
        }
        catch (Exception e)
        {
            Debug.LogError("send msg is fail : " + e);
            Close();
        }
    }
    public byte[] PackData(MsgBase msg)
    {
        //len+prto+data
        byte[] protoByte = BitConverter.GetBytes((int)msg.Proto);
        using (var ms = new MemoryStream())
        {
            Serializer.Serialize(ms, msg);
            Debug.Log("serializer msg");
            byte[] data = ms.ToArray();
            byte[] len = BitConverter.GetBytes(data.Length + protoByte.Length);
            return len.Concat(protoByte).Concat(data).ToArray();
        }
    }
出现了send msg is fail : System.InvalidOperationException: Unexpected sub-type: LoginMsg
打了序列化标签 但是不支持LoginMsg的序列化 运行到序列化的代码时 直接跳过
同学你好,可以参考一下:
https://blog.csdn.net/weixin_30791095/article/details/97466097
https://www.789zhao.com/blog/J8LOHZ9DORW7.html
https://www.5axxw.com/questions/content/lrkbsi
具体问题的话同学需要花时间再找找测试一下