Custom message not getting serialized properly after moving class to a standalone DLL

Hey fam,

I’m working on separating out some core code that my client and server share, including some of the custom messages I send back and forth. I have a bunch of classes derived from MessageBase that have been automatically getting serialized properly for quite some time.

However, after I moved these classes into their own DLL (with references to UnityEngine.Networking.dll) they don’t seem to be getting serialized. Any message I send, all the fields are null on the server-side.

If I override Serialize and Deserialize, providing my own serialization, it works fine.

Is there another reference I need to include in the standalone DLL for this to work properly? I have no idea how to debug since none of the Unity code is available to me, and no errors are thrown.

Interesting…so, after some digging, this is what I discovered:

MessageBase doesn’t have an actual implementation of Serialize and Deserialize - it seems like those might be codegen’d in Unity somehow as a post-build step. As a result, having network message definitions in your own library means you need to handle serialization yourself.

In my situation, I’m ok with that I guess. I created a class (child of MessageBase) that serializes to-from JSON and all my message classes derive from that instead.

Everything seems to be working now.

I wish there was something built into the networking library though rather than coupling that codegen to Unity itself.