- Home /
iOS JIT compile error on Generic method called with basic types (int, bool, float)
I have a generic method like this:
public class MyClass
{
public T MyMethod<T>(string arg)
{
return default(T);
}
}
When I try to call the method like this:
int someInt = MyClassInstance.MyMethod<int>("some_string");
I get the following error:
Attempting to JIT compile method 'MyClass.MyMethod<int> (string)' while running with --aot-only.
This also happens to bool and float types but it works for string.
Would you guys know why this happens? Thanks!
Answer by steakpinball · Jan 29, 2015 at 02:42 PM
This happened because just-in-time (JIT) compilation does not work on iOS. All code must be ahead-of-time (AOT) compatible. default()
sometimes uses JIT. When this happens, you will have to write the code in such a way to remove the use of default()
. I can't predict if it will or won't.
I will update this answer if I figure out more.
Interesting. I wasn't aware Dictionary was using it. I ran some test and found there are some instance where it does work, but can't see why it does or doesn't. If it works for you, Great.