#Custom Serializer Fails After Moving to Separate Assembly Definition

13 messages · Page 1 of 1 (latest)

jaunty magnet
#

Hey I tried moving a custom serializer from the main Assembly-CSharp into it's own assembly definition, but now I get these errors. I have both Fishnet.CodeGen and Fishnet.Runtime referenced. From the guide it sounds like this should work, but maybe I'm misunderstanding how this works.
I have [UseGlobalCustomSerializer] added to the type I'm trying to serialize.
I'm on version 4.6.18R of fishnet and version 2023.2.22f1 of Unity.

I also tried keeping the custom serializer in the main Assembly-CSharp, but I still got the same errors.

Any help would be really appreciated :)

frozen abyss
#

Hey there!
Do you have some code showing your custom serializer?

#

Since you mentioned that it's giving errors even when in the main assembly, perhaps it's just an issue in how it's setup

jaunty magnet
#

Sorry for the late response.
Here is the serializer

namespace AVR.Networking
{
    public static class NetworkScriptableObjectSerializer
    {
        public static void WriteNetworkScriptableObject(this Writer writer, NetworkScriptableObject value)
        {
            int id = NetworkScriptableObject.GetId(value);
            writer.WriteInt32(id);
        }

        public static NetworkScriptableObject ReadNetworkScriptableObject(this Reader reader)
        {
            int id = reader.ReadInt32();
            return NetworkScriptableObject.GetById(id);
        }
    }
}

The class to be serialized looks roughly like this:

namespace AVR.Networking
{
    [UseGlobalCustomSerializer]
    public abstract class NetworkScriptableObject : ScriptableObject
    {
        // Logic for giving each scriptible object a unique id
    }
}

To avoid any confusion what works and what doesn't work (on my side):
Serializable class and serializer both in main assembly: Works
Serializable class and serializer both in the same custom assembly: Throws the errors
Serializable class in custom assembly and serializer in main assembly: Throws the errors
Serializable class in main assembly and serializer in custom assembly: Can not compile because custom assembly can not reference main assembly

#

The reason why I would want to move these to a custom assembly is so other assemblies can use it.

frozen abyss
frozen abyss
frank jacinth
#

Hi, it seems like I stumbled over the same or a similar problem. I wrote a fix for it. I don't think it will or can be adopted as it is, but until it is fixed, it can be used as a temporary solution. I uploaded my commit that solves the problem to GitHub. The new attribute is written to the class to be serialized. With “assemblyName” you specify the name of the assembly definition. It should look like that in the Screenshot.

Here is the link:
https://github.com/FirstGearGames/FishNet/compare/main...Tenous-TV:FishNet:main

Hope this helps ✌️

GitHub

FishNet: Unity Networking Evolved. . Contribute to FirstGearGames/FishNet development by creating an account on GitHub.

jaunty magnet
jaunty magnet
#

I think it worked!
Just one strange thing is that it does't seem to work when I have the class in a namespace, but I can live with that.

jaunty magnet
frozen abyss