title: C# Convert ot Cast ExpandoObject to Specific Class Object
body: <p>I have a problem to cast or convert ExpandoObject to Object that is specific class in C# project.</p>
  <p>Class of Object:</p>
  <pre><code>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; }
  }
  </code></pre>
  <p>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.).</p>
  <p>In my problem, I need to cast or convert ExpandoObject that I got (It have type PlayerData before) to PlayerData in client side.</p>
  <p>Line that cast type :</p>
  <pre><code>PlayerData MyData = (PlayerData)Data;
  </code></pre>
  <p>And it return error :</p>
  <pre><code>System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
  </code></pre>
  <p>How can I fixed it and cast or convert it correctly?</p>
  <p><em><strong>Note</strong></em>
  // When I print &quot;Data.GetType()&quot; it return &quot;System.Dynamic.ExpandoObject&quot;</p>