Great work! But… there is some issues.
I try to make deserialization like this:
levelSettings = JsonConvert.DeserializeObject<Dictionary<string, LevelBase>>( levelSettingsFile.text, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto } );
Where LevelBase is base class for three other classes. In serialized string I have derived classes:
"1_1": {
"$type": "LevelRegular, Assembly-CSharp",
"moneyReward": 100,
"resources": {
"clover": 1
},
"id": "1_1",
"duration": -1
},
"1_2": {
"$type": "LevelRegular, Assembly-CSharp",
"moneyReward": 800,
"resources": {
"clover": 3,
"red_grape": 3
},
"id": "1_2",
"duration": 150.0
}
}
Aaaand when I run this code on iOS device, I get this:
(Filename: /Applications/buildAgent/work/cac08d8a5e25d4cb/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 54)
ExecutionEngineException: Attempting to JIT compile method 'System.Collections.Generic.GenericEqualityComparer`1<Newtonsoft.Json.Serialization.DefaultSerializationBinder/TypeNameKey>:.ctor ()' while running with --aot-only.
at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
at System.Collections.Generic.EqualityComparer`1[Newtonsoft.Json.Serialization.DefaultSerializationBinder+TypeNameKey]..cctor () [0x00000] in <filename unknown>:0
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for System.Collections.Generic.EqualityComparer`1
at System.Collections.Generic.Dictionary`2[Newtonsoft.Json.Serialization.DefaultSerializationBinder+TypeNameKey,System.Type].Init (Int32 capacity, IEqualityComparer`1 hcp) [0x00000] in <filename unknown>:0
at System.Collections.Generic.Dictionary`2[Newtonsoft.Json.Serialization.DefaultSerializationBinder+TypeNameKey,System.Type]..ctor () [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Utilities.ThreadSafeStore`2[Newtonsoft.Json.Serialization.DefaultSerializationBinder+TypeNameKey,System.Type].AddValue (TypeNameKey key) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Utilities.ThreadSafeStore`2[Newtonsoft.Json.Serialization.DefaultSerializationBinder+TypeNameKey,System.Type].Get (TypeNameKey key) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.DefaultSerializationBinder.BindToType (System.String assemblyName, System.String typeName) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue) [0x00000] in <filename unknown>:0
Rethrow as JsonSerializationException: Error resolving type specified in JSON 'LevelRegular, Assembly-CSharp'.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary (IWrappedDictionary dictionary, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonDictionaryContract contract, System.String id) [0x00000] in <filename unknown>:0
(Filename: Line: -1)
Any ideas?