using dynamic keyword with il2cpp

After a big rework, using the dynamic keyword, I found out that i can only use it with mono:

Since i also want to release on iOS switching to mono is no option.
Is there any workaround for using the dynamic keyword?

@thomh_unity as you have already suggested, some kind of warning would be really helpful.

looks like i have a few days of refactoring ahead of me because in the editor-play mode everything runs fine :confused:

No there is no workaround. The dynamic type heavily relies on runtime code generation and analysis which is completely out of the question for AOT platforms. IL2CPP cross compiles your compiled managed code from IL (.NET’s Intermediate Language) to C++ code. So everything has to be statically typed. Even generics which are usually bound at runtime are analysed and resolved at compile time. This is not possible for dynamic since the types are not known at compile time.

While warnings can be quite useful in some cases, I don’t think this will happen. There are countless of things you should be aware of that are not supported on certain platforms or that you should generally avoid. The Unity editor runtime always runs on the Mono runtime. So obviously there may be differences to the build version of your game depending on the target platform.

Eric Lippert (one of the designers of the C# compiler) has a great SO post on how a method call on a dynamic object works. Knowing the tools you’re using is your reponsibility :slight_smile: