pizheng/protobuf-net

Dictionary direct class members deserialize as null

Closed this issue · 2 comments

I'm using the latest stable 2.0 release and direct class member Dictionary are 
deserialized as null in this example:

public class Test
{
  // Deserializes as null
  public Dictionary<long, string> dict = new Dictionary<long, string>();


  // Deserializes correctly
  public Dictionary<long, string> dict2 { get; set; }
  private Test()
  {
    this.dict2 = new Dictionary<long, Foo>();
  }
}

I was dumbfounded as to why cloning dictionaries directly worked fine but 
putting them into a class caused them to always be nulled out during 
deserialization, but once I looked thought your dictionary unit test code I 
noticed that you only tested their serialization via property getters and 
setters and not direct fields.

I apologize for any typos - only my phone has web access at the moment!

Original issue reported on code.google.com by cold...@gmail.com on 21 Jun 2011 at 5:01

Hah, I forgot to include the ProtoContract and ProtoMember attrubes in the 
example!  I used their default forms with no special options.

Original comment by cold...@gmail.com on 21 Jun 2011 at 5:08

Added as a test, but it already passes locally - so this has already been 
addressed (just: not deployed)

Original comment by marc.gravell on 21 Jun 2011 at 6:14

  • Changed state: Fixed