kcp 我把一个类的对象序列化成byte[] ,传送时,发生了错误

blmhpbnm  于 2022-11-02  发布在  其他
关注(0)|答案(3)|浏览(110)

System.ArgumentException: Source array was not long enough. Check the source index, length, and the array's lower bounds.
Parameter name: sourceArray
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
at SGF.Network.KCP.KCP.Send(Byte[] buffer, Int32 bufferSize) in E:\gitvs\KcpServer\KcpServer\KcpServer\Network\KCP\kcp.cs:line 353

ltqd579y

ltqd579y1#

我是这样序列化的

public static byte[] Object2Bytes(this object obj)
    {
        byte[] buff;
        using (MemoryStream ms = new MemoryStream())
        {
            IFormatter iFormatter = new BinaryFormatter();
            iFormatter.Serialize(ms, obj);
            buff = ms.GetBuffer();
        }
        return buff;
    }
vktxenjb

vktxenjb3#

你该去 kcp 的.net项目那里提bug啊

相关问题