IL2CPP Dictionary deserialization issue


I build my project with scripting backend as IL2CPP(Unity 4.6.3 and Xcode 6.1.1). On building the project it is unable to deserialise the dictionary.

The error is :
SerializationException: Could not find type 'System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=, '.
at System.Runtime.Remoting.Messaging.RemotingSurrogate.GetObjectData (System.Object obj, System.Runtime.Serialization.SerializationInfo si, StreamingContext sc) [0x00000] in :0
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadType (System.IO.BinaryReader reader, TypeTag code) [0x00000] in :0
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadTypeMetadata (System.IO.BinaryReader reader, Boolean isRuntimeObject, Boolean hasTypeInfo) [0x00000] in :0
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectInstance (System.IO.BinaryReader reader, Boolean isRuntimeObject, Boolean hasTypeInfo, Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) [0x00000] in :0
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject (BinaryElement element, System.IO.BinaryReader reader, Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) [0x00000] in :0
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (System.IO.BinaryReader reader) [0x00000] in :0
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (BinaryElement elem, System.IO.BinaryReader reader, Boolean readHeaders, System.Object& result, System.Runtime.Remoting.Messaging.Header& headers) [0x00000] in :0
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) [0x00000] in :0
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) [0x00000] in :0
at AutoSpriteControlBase.IUIObject.get_name () [0x00000] in :0
at EncodeData.Decode[FeedAnimalsTime] () [0x00000] in :0
at GameState.get_ActualGameState () [0x00000] in :0
at SplashSceneScript+c__Iterator10.MoveNext () [0x00000] in :0
at Replacements.MSCompatUnicodeTable.get_IsReady () [0x00000] in :0
at UnityEngine.MonoBehaviour.StartCoroutine_Auto (IEnumerator routine) [0x00000] in :0
at UnityEngine.MonoBehaviour.StartCoroutine (IEnumerator routine) [0x00000] in :0
at SplashSceneScript.LoadNextScene () [0x00000] in :0
at Replacements.MSCompatUnicodeTable.get_IsReady () [0x00000] in :0

(Filename: currently not available on il2cpp Line: -1)

There is no such issue when building the project with Mono(2.x) as scripting backend. I request you to please look into the issue as my game is completed and it is working fine for 32-bit support

It looks like this problem occurs because a generic dictionary type cannot be constructed at run time by the serializer. You can give IL2CPP some hints about what generic types will be needed a runtime, and likely avoid this problem, but following the process described in this forum post:

Note that you will need at least version 4.6.3p4 to make this work.

@Josh we have tried these entries in text file and it didn’t work out. Can you see any problem with namespaces or their types ? do you have any alternative solution ?

System.Collections.Generic.Dictionary`2[System.Enum , UnityEngine.Object]  **on behalf of  Dictionary<Enum value , MonoBehaviour>**
System.Collections.Generic.Dictionary`2[System.Int32, System.Collections.Generic.List<T>]  **on behalf of  Dictionary<int value , list <int>>**
System.Collections.Generic.Dictionary`2[System.Enum, System.Single]  **on behalf of  Dictionary<Enum value , Float value>**
System.Collections.Generic.Dictionary`2[System.Enum, System.Object]   **on behalf of  Dictionary<Enum value , Scriptable Class>**

Recently we released Runtime Serialization for Unity plugin which handles all the above mentioned issues, like

  • Serializing dictionary object of type
  • Serializing base class instance and while deserialising you will fetch the original derived class object.

Now you may ask, how’s that possible ???

Actually when we serialise an object of any given type, we serialize its metadata along with the value. So this extra metadata serialization done by our plugin makes it possible to retrieve the original object after deserializing.