- Home /
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;
Answer by Nomenokes · Jul 20, 2018 at 08:08 PM
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.
It was in a class like you suggested I just didn't include the code. I pasted your code example into a new cs file named Expander.cs and get the same error.
Hmm. Can you post your entire class of code please? The compiler tends to be bad about where exactly the error is.
using System.Dynamic;
public class expander : $$anonymous$$onoBehaviour {
dynamic myEo = new ExpandoObject();
myEo.a="a";
}
...it needs to be in a method, too...
public class foo {
public void DoSomething() {
dynamic myEo = new ExpandoObject();
myEo.a="a";
}
}
Answer by tomasofen · Sep 14, 2019 at 11:27 AM
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 Ö.Ö
Your answer
Follow this Question
Related Questions
What is the most efficient way to dynamically add a component, based on a string passed in. 1 Answer
Is it possible to have continuous collision detection with dynamic points on Edge Colliders? 0 Answers
Instantied GameObject Prefab doesn't have a height 0 Answers
Best way to dynamically assign a camera? 0 Answers
How to access the data in a list that save any class inside 1 Answer