title: ASP.Net Web API 2 async method fails for JSON response
body: <p>I have below async method in Web API 2:</p>
  
  <pre><code>[System.Web.Http.HttpGet]
  public async Task&lt;TestResultResponse&gt; GetAll()
  {
      DBService repo = new DBService();
      TestResultResponse response = new TestResultResponse();
  
      response.Tests = await repo.GetAll(); // call to async method
  
      return response;
  }
  </code></pre>
  
  <p>This API method works fine if request content type is XML ,i.e, response is returned in XML format. However, when I try to get JSON response, I get StackOverflow exception. In VS 2013, I get only below details as part of exception:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.StackOverflowException'
    occurred in Newtonsoft.Json.dll</p>
  </blockquote>
  
  <p>I get this exception only when I request for response in JSON. It works fine for XML response. For sync methods, JSON works fine. It seems to be issue only with JSON and aync methods. </p>
  
  <p>Any suggestions on how to fix this error for JSON response ?</p>
  
  <p><strong>Update 1:</strong> As requested below is list of classes used for response:</p>
  
  <pre><code>public class TestResultResponse
  {
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public List&lt;Test&gt; Tests { get; set; }
  }
  
  public class Test : BaseEntity
  {
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public string Content { get; set; }    
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public Test InnerDoc { get; set; }
  }
  
  public class BaseEntity
  {
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public ObjectId Id { get; set; }    
      public int Status { get; set; }    
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public string CreatedBy { get; set; }    
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public string UpdatedBy { get; set; }    
      public DateTime CreatedDate { get; set; }    
      public DateTime UpdatedDate { get; set; }
  }
  </code></pre>
  
  <p>You can find XML response at <a href="http://pastebin.com/Ys7DeZPc" rel="nofollow">http://pastebin.com/Ys7DeZPc</a></p>