WebGL build doesn't work 2017.1 (ExecutionEngineException)

ExecutionEngineException: Attempting to call method ‘GetActionDelegate’ for which no ahead of time (AOT) code was generated.
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation
(Filename: currently not available on il2cpp Line: -1)

Delegate GetActionDelegate<T>(object handlerValue)
{
    var method = handlerValue.GetType().GetMethod("Invoke");

    return new Action<T>(value =>
    {
        method.Invoke(handlerValue, new object[] { value });
    });
}

Does anyone know what to do?

This can happen with an AOT compiler like IL2CPP. We need to know all of the possible types T at compile time. Often with generics that is not possible. To troubleshoot this, first we need to determine what the type of T is when the exception occurs. You can probably do with with logging:

Debug.Log(typeof(T).FullName);

Once we know that, then you can change the code to make an explicit call to GetActionDelete with that type. That will allow IL2CPP to see that type is used, and generate the proper code for it to be called at runtime.

Thanks, I rewrote the code so that the T type was known at the compilation stage. Now everything works.

1 Like