Skip to content

Deserializing a Unity network message giving  #237

@MostHated

Description

@MostHated

I am having issues trying to deserialize a NetworkMessage sent in Unity but I am running into an issue which is coming back with the error of :

     [Exception] NullReferenceException: Object reference not set to an instance of an object
    LZ4MessagePackSerializer.Deserialize[T]() Assets/Scripts/MessagePack/LZ4/LZ4MessagePackSerializer.cs:141
    139:   public static T Deserialize<T>(byte[] bytes, IFormatterResolver resolver)
    140:   {
    -->141:       return DeserializeCore<T>(new ArraySegment<byte>(bytes, 0, bytes.Length), resolver);
    142:   }

Here is my overall process.
I send to the serializer and then pass it on.

var msg = NOC.Serialize(opCode, opReqCode, parameters);
con.SendByChannel(MsgType.InternalHighest+1, new ByteArray() { Data = msg }, channel);

Here is the actual serialization process.

public static byte[] Serialize(byte msgType, byte opCode, Dictionary<byte, object> parameters)
    {
        var tempmsg = new object[] {msgType, opCode, parameters };
        var serializedmsg = LZ4MessagePackSerializer.Serialize(tempmsg);
        Debug.Log("Msg Serialized");
        return serializedmsg;
    }

Then on the server side I have this.

    private void RegisterHandlers()
    {
        NetworkServer.RegisterHandler(MsgType.InternalHighest+1, IncomingOperationHandler);
    }

    private void IncomingOperationHandler(NetworkMessage msg)
    {
        var msg1 = msg.ReadMessage<ByteArray>().Data;
        var deserial = NOC.Deserialize(msg1);
        Debug.Log(deserial);
    }

and here is the deserialization process

public static object[] Deserialize(byte[] deserial)
    {
        var deserializedmsg = LZ4MessagePackSerializer.Deserialize<object[]>(deserial);
        Debug.Log("Msg Deserialized");
        return deserializedmsg;
    }

I am not sure what is going on to bring that message. When I go to the method it is showing in the log it has this

public static T Deserialize<T>(byte[] bytes, IFormatterResolver resolver)
    {
        return DeserializeCore<T>(new ArraySegment<byte>(bytes, 0, bytes.Length), resolver);
    }

Should it not be getting sent to this?

public static T Deserialize<T>(byte[] bytes)
    {
        return Deserialize<T>(bytes, null);
    }

If anyone has any insight I would greatly appreciate it!
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions