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 w[136512-error.txt|136512]e 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.

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.

Confirm the issue with dynamic variable issue while using il2cpp on Unity 2019.2.17f1 and 2019.3.0f5

I just had this issue when trying to deserialize some json to a dynamic type. What solved it for me was deserializing to JTokens instead

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.