Using "Dynamic" Keyword
Hi,
I used "dynamic" as the return type for a method in C#. When the game is imported to xCode, it doesn't run, and throws an exception as shown in the attachment. The code works as expected in Android Studio. Can you please help me if there is a workaround to use "dynamic" keyword? Or if there is a possible replacement for it?
Also wlink texte have tried the solution as explained at https://answers.unity.com/questions/1413144/c-dynamic-variables-as-of-2017.html But unfortunately it didn't work.
BR, Saikrishna.
Is there a workaround that lets me use it? I don't want to refactor my code to avoid using dynamic...
Answer by thomh_unity · May 24, 2019 at 01:15 PM
Hi @saikrishna0791,
Using the type 'dynamic' is supported in .NET 4.X but only when using mono as your scripting backend.
The reason you're seeing a failure when you build for iOS is because it does not support using mono as a backend and so will default to il2cpp. If you also switch to il2cpp when you build for Android you will see the same failure as on iOS.
I've spoken with one of our developers and we think there could be some better feedback or error message when trying to use the 'dynamic' type with il2cpp rather than just failing. I will look into this.
Best regards,
Thom.
Answer by NikolaiS · Jan 19, 2020 at 03:47 PM
Confirm the issue with dynamic variable issue while using il2cpp on Unity 2019.2.17f1 and 2019.3.0f5
Answer by drorriov · Jul 26, 2019 at 09:44 AM
Also had this issue using IL2CPP, worked fine with Editor, got an error on Android. Spent hours trying to figure it out until I lucky encountered this post. Now I need to redo code by removing the dynamic implementation. The issue should be fixed or improve error message as @saikrishna0791 suggested.
Also, opened a bug report.