I have a mobile Android game on the market, and I’m trying to port it to iOS. I have the game running on my test device, but I’m getting the following AOT exception when I try to save game progress:
EXCEPTION: SaveState - Attempting to JIT compile method 'System.Collections.Generic.Dictionary`2<string, object>:Do_CopyTo<System.Collections.Generic.KeyValuePair`2<string, object>, System.Collections.Generic.KeyValuePair`2<string, object>> (System.Collections.Generic.KeyValuePair`2<string, object>[],int,System.Collections.Generic.Dictionary`2/Transform`1<string, object, System.Collections.Generic.KeyValuePair`2<string, object>>)' while running with --aot-only.
at System.Collections.Generic.Dictionary`2[System.String,System.Object].CopyTo (System.Collections.Generic.KeyValuePair`2[] array, Int32 index) [0x00000] in <filename unknown>:0
at System.Collections.Generic.Dictionary`2[System.String,System.Object].GetObjectData (System.Runtime.Serialization.SerializationInfo info, StreamingContext context) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.GetObjectData (System.Object obj, System.Runtime.Serialization.Formatters.Binary.TypeMetadata& metadata, System.Object& data) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObject (System.IO.BinaryWriter writer, Int64 id, System.Object obj) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObjectInstance (System.IO.BinaryWriter writer, System.Object obj, Boolean isValueObject) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteQueuedObjects (System.IO.BinaryWriter writer) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObjectGraph (System.IO.BinaryWriter writer, System.Object obj, System.Runtime.Remoting.Messaging.Header[] headers) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph, System.Runtime.Remoting.Messaging.Header[] headers) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph) [0x00000] in <filename unknown>:0
at EncryptionManager.EncryptFile (System.String _path, System.Object _data, System.Byte[] _key) [0x00000] in <filename unknown>:0
at StateManager.SaveState () [0x00000] in <filename unknown>:0
I understand the issue, and I’ve tried creating AOT hints for the compiler with no luck. Can anyone suggest a fix? I don’t want to incorporate another library or package because I want to keep the Android and iOS code base the same, and I already have Android users with save data.
Here is my current setup:
public static void EncryptFile(string _path, object _data, byte[] _key = null)
{
// Check parameters
if (_data == null) return;
if (_path == null || _path.Length <= 0) return;
// Create AES service provider
using (RijndaelManaged aes = new RijndaelManaged())
{
// Set aes paramaters
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.ISO10126;
// Set key
aes.Key = _key;
// Set iv
aes.GenerateIV();
// Create file stream
using (FileStream file = new FileStream(_path, FileMode.Create))
{
// Write iv to file
file.Write(aes.IV, 0, aes.IV.Length);
// Create crypto stream
using (CryptoStream crypto = new CryptoStream(file, aes.CreateEncryptor(aes.Key, aes.IV), CryptoStreamMode.Write))
{
// Serialize data
BinaryFormatter bin = new BinaryFormatter();
bin.Serialize(crypto, _data);
}
}
}
}
I’m passing in a Dictionary< string, object > for _data.