leejw51 / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
0 stars 0 forks source link

automatic tuple detection breaks detection and serialization/deserialization on Unity3D platform #234

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please include an e-mail address if this might need a dialogue!
==============

What steps will reproduce the problem?
1. Download Unity3d ( unity3d.com )
2. Create a new project
3. In the project tab, right click, "import new asset...", select 
protobuf-net.dll
3. In the project-tab, create a new script with content of Test.cs
4. Drag the script to the "Main Camera" in the Hierarchy Tab
5. Press the Play Button on the top.

============= Test.cs ==============
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using ProtoBuf.Meta;

public class Test : MonoBehaviour {
    void Start () {

        Dictionary<int, string> dict = new Dictionary<int, string>();
        dict[7] = "HelloWorld";

        Dictionary<int, string> dict2 = (Dictionary<int, string>)RuntimeTypeModel.Default.DeepClone(dict);
        foreach (int key in dict2.Keys) {
            Debug.Log("Key #: " + key + " ==> " + dict2[key]);
        }
    }

    void Update () {
    }
}
==============================

What is the expected output? What do you see instead?
Expected output ( in the console tab ) is:
Key #:7 ==> HelloWorld
instead it is
InvalidOperationException: Type is not expected, and no contract can be 
inferred, etc.

What version of the product are you using? On what operating system?
Latest trunk from svn.

Please provide any additional information below.
After a lot of searching on the wrong side ( the server ) I could trace the 
problem to the new automatic tuple detection, more specific the check on 
Propertys. It seems the Mono environment that Unity3D uses has some Property(s) 
writeable, which breaks the detection code.

When i change line 526 ( r443 ) from
if (!prop.CanRead || prop.CanWrite) {
to 
if (!prop.CanRead ) {
everything works as expected.
I don't know if the check for non-writeability is really required, maybe you 
have more information about this? For now i'll just change it here locally and 
build the lib myself, but I hope this can be changed in the trunk as well. 
Maybe the default Mono implementation of KeyValuePair has the same problems?

For more information about this problem or Unity feel free to contact me at 
aneumann0815@googlemail.com

P.S.: Great work with protobuf-net, impressive work.

Original issue reported on code.google.com by ANeumann...@googlemail.com on 25 Sep 2011 at 3:28

GoogleCodeExporter commented 9 years ago
It breaks detection and serialization/deserialization of KeyValuePairs ( and 
dictionarys ) of course... Just to clarify.

Original comment by ANeumann...@googlemail.com on 25 Sep 2011 at 3:35

GoogleCodeExporter commented 9 years ago
Thanks for the report. I will investigate this later today.

Original comment by marc.gravell on 25 Sep 2011 at 4:46