Error trying to use ExpandoObject in Unity 2018.1

I get an error when trying to use expandoObject with Unity 2018.1 free edition

using System.Dynamic;
        dynamic MyDynamic = new System.Dynamic.ExpandoObject();
        MyDynamic.A = "A";

The error is in the line: MyDynamic.A=“A”;
Unexpected symbol `=’ in class, struct, or interface member declaration using System.Dynamic;

You need to have your code inside a class, which you do not have a declaration of. The compiler thinks that using System.Dynamic is your class declaration. For example:

using System.Dynamic;

public class Expander : MonoBehaviour {
     dynamic MyDynamic = new System.Dynamic.ExpandoObject();
     MyDynamic.A = "A";
}

The class needs to be of the same name of the file that it’s in. This class would need to have a file name of Expander.cs.


I’m not sure what ExpandoObject is, but the error is a compiler error with your code, not with ExpandoObject.

dynamic “ExpandoObject” does not work on Unity as it is based on Mono, isn’t it?

The last time i tried they could be declared, but failed when trying to modify their “dinamic” properties like:

myEo.a=“a”;

It would be great if someone tells me that i’m wrong and that this can be used Ö.Ö