title: C# seralize dynamic object with EF result in it (Create JSON object from dynamic c# object)
body: <p>I have this code:</p>
  
  <pre><code>var companyDetails = db.tbl_Mallstore.ToList();
  
  dynamic result = new System.Dynamic.ExpandoObject();
  result.count = 1;
  result.company = companyDetails.FirstOrDefault();
  
  JavaScriptSerializer serializer = new JavaScriptSerializer();
  
  string output = serializer.Serialize(result);
  </code></pre>
  
  <p>That throws the error:</p>
  
  <blockquote>
    <p>A circular reference was detected while serializing an object of type 'eDurar.Models.tbl_Mallstore </p>
  </blockquote>
  
  <p>In this case it works:</p>
  
  <pre><code>dynamic result = new System.Dynamic.ExpandoObject();
  result.count = count;
  result.store_name = companyDetails.FirstOrDefault().store_name;
  
  JavaScriptSerializer serializer = new JavaScriptSerializer();
  string json = serializer.Serialize(result);
  </code></pre>