Templates/Generic - AOT problems

Hi,

I ran into some problem using generics/templates in Unity while deploying my code to iPad.

Here is some simple code :

using UnityEngine;"
using System.Collections;
using System.Collections.Generic;

class TestValue<T>
{
	public T _value;
	
	public TestValue(T _p) 
	{
		_value = _p;
	}
}

class TestDictonary<T>
{
	public Dictionary< TestValue<T>, int> _dic;
	
	public TestDictonary(T _p) 
	{
		_dic = new Dictionary<TestValue<T>, int>();
		_dic.Add(new TestValue<T>(_p), 2);
	}
	
	public void PrintAll()
	{
		Debug.Log( _dic.Values.Count );
	}
}

public class TestLogging : MonoBehaviour 
{
	void Awake()
	{
		TestDictonary<string> myDictionary = new TestDictonary<string>("Yep");		
		myDictionary.PrintAll();
	}
}

While running this on my iPad i got:

ExecutionEngineException: Attempting
to JIT compile method
‘System.Collections.Generic.Dictionary2<TestValue1,
int>:.ctor ()’ while running with
–aot-only.

I have done some research and it seems a common problem ( http://ios.xamarin.com/Documentation/Limitations )

What I dont get is how could I discover that before (ie not at runtime) ?
Why is there no errors reported during compilation ?

The compilation under unity is done with the flag --aot=full … so why such cases aren’t be discovered there ?

Here is the Unity command line i had discovered in the logs - note how AOT is set to full.

AOT cross compiler: /Applications/Unity.app/Contents/BuildTargetTools/iPhonePlayer/mono-xcompiler --debug --aot=full,asmonly,write-symbols,soft-debug,static,outfile=“Assembly-CSharp.dll.s” “Assembly-CSharp.dll” current dir : /Users/XXXX/Dev/Unity/TestLogging/Temp/StagingArea/Data/Managed

Actually, according to the limitations document you referenced it looks like it should work, as your TestValue is a reference type and not a value type.

However, you could try providing your own IEqualityComparer<TestValue> to the dictionary constructor and see if that helps.

Unfortunately, I have not been able to find a reliable way of determining if a piece of code code will run on iOS without actually uploading the app and running it.