Closed Frankinstien4444 closed 2 years ago
I have the following objects:
`[Serializable] public class KeyGroupMap { [DataMember] public String GroupName { private set; get; }
[DataMember] public List<KeyMap> KeyNameSpaces { private set; get; } [DataMember] public List<KeyMap> ReferenceNameSpace { set; get; }
}`
`[Serializable] public class KeyMap { [DataMember] public Guid ID { private set; get; }
[DataMember] public List<PropertyPath> KeyMaps { set; get; }
`[Serializable] public class PropertyPath { [DataMember] public String ClassType { set; get; }
[DataMember] public String Property { set; get; } }`
The KeyGroupMap serializes to this:
{ "$types": { "KeyIndexManager.Models.KeyGroupMap, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null": "1", "KeyIndexManager.Models.KeyMap, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null": "2", "KeyIndexManager.Models.PropertyPath, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null": "3" }, "$type": "1", "GroupName": "Key Group 0", "KeyNameSpaces": [ { "$type": "2", "ID": "B6BnRLCT40KC78Y1aj+98Q==", "KeyMaps": [ { "$type": "3", "ClassType": "DictionaryIndexer.WordDefinition, DictionaryAccessor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "Property": "Word" } ] } ], "ReferenceNameSpace": [ { "$type": "2", "ID": "z5svCIQYIkCzkTFB6Cepaw==", "KeyMaps": [ { "$type": "3", "ClassType": "DictionaryIndexer.WordDefinition, DictionaryAccessor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "Property": "ID" } ] } ] }
But it failed to deserialize. However, I have it serialized within a list I get this serialization:
[ { "$type": "KeyIndexManager.Models.KeyGroupMap, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "GroupName": "Key Group 0", "KeyNameSpaces": [ { "$type": "KeyIndexManager.Models.KeyMap, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "ID": "B6BnRLCT40KC78Y1aj+98Q==", "KeyMaps": [ { "$type": "KeyIndexManager.Models.PropertyPath, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "ClassType": "DictionaryIndexer.WordDefinition, DictionaryAccessor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "Property": "Word" } ] } ], "ReferenceNameSpace": [ { "$type": "KeyIndexManager.Models.KeyMap, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "ID": "z5svCIQYIkCzkTFB6Cepaw==", "KeyMaps": [ { "$type": "KeyIndexManager.Models.PropertyPath, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "ClassType": "DictionaryIndexer.WordDefinition, DictionaryAccessor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "Property": "ID" } ] } ] } ]
And this works perfectly. It's only when it uses those type indexes does it fail and I don't know why the first serialization should de-serialize. Any ideas?
Never mind I just solved it. Some of the fields had private setters. But weird the list serialization worked...
I have the following objects:
`[Serializable] public class KeyGroupMap { [DataMember] public String GroupName { private set; get; }
}`
`[Serializable] public class KeyMap { [DataMember] public Guid ID { private set; get; }
}`
`[Serializable] public class PropertyPath { [DataMember] public String ClassType { set; get; }
The KeyGroupMap serializes to this:
{ "$types": { "KeyIndexManager.Models.KeyGroupMap, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null": "1", "KeyIndexManager.Models.KeyMap, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null": "2", "KeyIndexManager.Models.PropertyPath, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null": "3" }, "$type": "1", "GroupName": "Key Group 0", "KeyNameSpaces": [ { "$type": "2", "ID": "B6BnRLCT40KC78Y1aj+98Q==", "KeyMaps": [ { "$type": "3", "ClassType": "DictionaryIndexer.WordDefinition, DictionaryAccessor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "Property": "Word" } ] } ], "ReferenceNameSpace": [ { "$type": "2", "ID": "z5svCIQYIkCzkTFB6Cepaw==", "KeyMaps": [ { "$type": "3", "ClassType": "DictionaryIndexer.WordDefinition, DictionaryAccessor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "Property": "ID" } ] } ] }
But it failed to deserialize. However, I have it serialized within a list I get this serialization:
[ { "$type": "KeyIndexManager.Models.KeyGroupMap, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "GroupName": "Key Group 0", "KeyNameSpaces": [ { "$type": "KeyIndexManager.Models.KeyMap, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "ID": "B6BnRLCT40KC78Y1aj+98Q==", "KeyMaps": [ { "$type": "KeyIndexManager.Models.PropertyPath, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "ClassType": "DictionaryIndexer.WordDefinition, DictionaryAccessor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "Property": "Word" } ] } ], "ReferenceNameSpace": [ { "$type": "KeyIndexManager.Models.KeyMap, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "ID": "z5svCIQYIkCzkTFB6Cepaw==", "KeyMaps": [ { "$type": "KeyIndexManager.Models.PropertyPath, KeyIndexManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "ClassType": "DictionaryIndexer.WordDefinition, DictionaryAccessor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "Property": "ID" } ] } ] } ]
And this works perfectly. It's only when it uses those type indexes does it fail and I don't know why the first serialization should de-serialize. Any ideas?