title: Serializing ExpandoObject with json.Net
body: <p>I have the following code, where <code>page.Fields</code> is an <code>ExpandoObject</code>. I'm iterating through some user-defined properties and adding them to an Expando, cast to an <code>IDictionary&lt;string,string&gt;</code> to allow me to add new field name / values dynamically, but when I set the <code>Fields</code> property to the value of <code>props</code>, serializing afterwards only gives names with blank values of <code>{}</code>. Why?</p>
  
  <pre><code>page.Fields.Foo = "asdf";
  var test = JsonConvert.SerializeObject(page); // shows Foo=asdf in the json
  
  // attach all fields to the page object, casting to an IDictionary to be able to add var names
  var props = new ExpandoObject() as IDictionary&lt;string, Object&gt;;
  foreach (string key in Request.Form.Keys)
  {
      if (key.StartsWith("Fields."))
      {
          var fieldName = key.Substring(key.IndexOf(".") + 1);
          props.Add(fieldName, Request.Form[key]);
      }
  }
  
  var test2 = JsonConvert.SerializeObject(props); // blank values of {}
  page.Fields = props as ExpandoObject;
  
  // loses the values for the Fields property
  test = JsonConvert.SerializeObject(page);
  </code></pre>
  
  <p><strong>UPDATE</strong> the curse of Nancy strikes, the <code>Request.Form</code> values turned out to be dynamic, so I had to <code>.ToString()</code> it to make it fit into the expected <code>IDictionary&lt;string,string&gt;</code></p>