I have a generic method for trying to get a generic value from a dictionary via key using my own TryGetValue
like (of course cropped a lot to the essential)
public class BaseExample
{
public virtual bool TryGetValue<T>(string key, out T value)
{
value = default;
return false;
}
}
public class Example : BaseExample
{
private Dictionary<string, Item> _items = new Dictionary<string, Item>();
public override bool TryGetValue<T>(string key, out T value)
{
value = default;
if (!GetItem(key, value, out var setting)) { return false; }
value = (T)setting.Value;
return true;
}
private bool GetItem<T>(string key, T value, out Item item)
{
item = null;
if (!_items.ContainsKey(key))
{
item = null;
return false;
}
item = _items[key];
return true;
}
}
This works in the Unity Editor but as soon as this is built to UWP and IL2CPP as soon as I try to run the method with e.g.
var value = example.TryGetValue<int>("SomeKey");
It throws a
System.ExecutionEngineException: Attempting to call method 'Example::TryGetValue<System.Int32>' for which no ahead of time (AOT) code was generated.
What could be the reason for this and how can I fix it?