- Home /
JIT compilation requirement for System.Reflection.PropertyInfo.GetValue?
Calling System.Reflection.PropertyInfo.GetValue on an AOT compiled platform when the API compatibility level is set to .NET 2.0 gives me the following error:
Unhandled Exception: System.ExecutionEngineException: Attempting to JIT compile method 'System.Reflection.MonoProperty:StaticGetterAdapterFrame (System.Reflection.MonoProperty/StaticGetter`1,object)' while running with --aot-only.
at System.Reflection.MonoProperty.GetValue (System.Object obj, System.Object[] index) [0x00000] in :0
The error does not occur when the API compatibility level is set to .NET 2.0 Subset. Is this expected behaviour or a Unity bug?
Here is my code
void Start()
{
System.Type type = System.Type.GetType("UnityEngine.iPhone, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
if (type != null)
{
System.Reflection.PropertyInfo property = type.GetProperty("generation");
if (property != null)
{
string text = property.GetValue(null, null).ToString().ToLower();
Debug.Log("text = " + text);
}
else
Debug.Log("property = null");
}
}
This was added to a new empty project in Unity 4.5.5 and deployed to a 1st generation iPad Mini running iOS 7.1.2.
This appears to be an issue in the $$anonymous$$onoProperty class. Looking at the source it looks like they put in conditionals for AOT compilation. I suspect maybe an edge case was missed. Either way it's in the core $$anonymous$$ono library so i don't know if opening a Unity bug would be fruitful. Did you open one?
Answer by mossyblog · Jan 08, 2016 at 02:51 PM
If you switch Unity to use Mono Subset, this should bypass that error. I'm still trying to isolate specifically why GetValue works in this subset... as from where i can tell Subset is a reduction in namespaces only on Mono..