I have a problem to cast or convert ExpandoObject to Object that is specific class in C# project.
Class of Object:
public class PlayerData {
public string Id {get; set;}
public string Phone { get; set; }
public Money Money { get; set; }
}
public class Money {
public int Cash { get; set; }
public int Bank { get; set; }
}
When in server sent some data (of type PlayerData) to client side, client see that data in class ExpandoObject. I can use this data as well (like Data.Id, Data.Phone etc.).
In my problem, I need to cast or convert ExpandoObject that I got (It have type PlayerData before) to PlayerData in client side.
Line that cast type :
PlayerData MyData = (PlayerData)Data;
And it return error :
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
How can I fixed it and cast or convert it correctly?
Note
// When I print Data.GetType()
it return System.Dynamic.ExpandoObject
ExpandoObject
, you solve it through proper serialization and deserialization – Gimmal