Sending dictionaries with custom types through RPCs

I'm trying to send a Dictionary through an RPC with the value being a custom class, and the key being an int.

I've managed to serialize the dictionary just fine, but Photon can't find the receiving RPC function on the other side.
PhotonView with ID 1 has no method "ReceiveInitData" that takes 1 argument(s): Dictionary`2

If I send a Dictionary<int, int> through, rather than Dictionary<int, MyClass>, there is no problem.

I've added functions to CustomTypes for serializing and deserializing the custom type, and I register the type with PhotonPeer. I also get no errors on the sending side.

Comments

  • You need to register your custom types, otherwise they won't exist.
  • As I said:
    JakobOerum wrote:
    ... , and I register the type with PhotonPeer.
    PhotonPeer.RegisterType(typeof(MyClass), (byte)'U', SerializeMyClass, DeserializeMyClass);
    
  • I realize I should have been more specific as two steps are involved in this case not just one, though the second one is no Photon thing, its a general .NET thing:

    1. Did you register it -> obviously as per your initial posting already yes :)
    2. As you want to send a Dictionary<,> you must actually write your serialization to handle the Dictionary<,> itself already (serialize the dictionary itself) as .NET does not support serialization of Dictionary<,> through the serializers (independent which one).
    Photon handles it for its own supported base types if I recall right but thats where it ends.
    Thats why you will normally only see Hashtable being used, they will work with custom types as they are serializable.
  • Photon does not use serializers. Once you registered a custom type, it should be usable anywhere but to be honest, I didn't check whether it works as type in a Dictionary.
    It would help if we could have a complete, minimal sample to reproduce the issue.
    Did you check the server side logs?
  • I fixed it by using Hashtables instead, but if we get time to set up a scenario that reproduces the error, I'll try and get it done.

    However, it seems that the serialization of custom types in dictionaries don't produce errors, as long as the type has been registered. Only the deserialization produces errors.