In MonoTouch, when creating a generic type that has a Dictionary that uses the type's generic type parameter for its values' type, the AOT compiler doesn't construct the required Dictionary type, resulting in a runtime error on an iOS device when it tries to invoke the JIT compiler.
public class Foo<T>
{
private Dictionary<int, T> d = new Dictionary<int, T>();
...
}
var foo = new Foo<string>(); // Runtime error.
There is a work-around (posted on the Catalysts blog) that involves explicitly declaring any constructed types required elsewhere in the program:
var x = new Dictionary<int, string>();
But that's a bit messy. Is there a better work-around?
Also, it seems to me that all the information is there at compile time, so the AOT compiler should be able to construct the required types. Is this therefore a compiler feature that is feasible (and we could possibly get in a future release)?
This has now been fixed, so no workaround is required: