title: HttpClient.GetAsync(...) never returns when using await/async
body: <p><strong>Edit:</strong> <a href="https://stackoverflow.com/questions/9895048/async-call-with-await-in-httpclient-never-returns">This question</a> looks like it might be the same problem, but has no responses...</p>
  
  <p><strong>Edit:</strong> In test case 5 the task appears to be stuck in <code>WaitingForActivation</code> state.</p>
  
  <p>I've encountered some odd behaviour using the System.Net.Http.HttpClient in .NET 4.5 - where "awaiting" the result of a call to (e.g.) <code>httpClient.GetAsync(...)</code> will never return.</p>
  
  <p>This only occurs in certain circumstances when using the new async/await language functionality and Tasks API - the code always seems to work when using only continuations.</p>
  
  <p>Here's some code which reproduces the problem - drop this into a new "MVC 4 WebApi project" in Visual Studio 11 to expose the following GET endpoints:</p>
  
  <pre><code>/api/test1
  /api/test2
  /api/test3
  /api/test4
  /api/test5 &lt;--- never completes
  /api/test6
  </code></pre>
  
  <p>Each of the endpoints here return the same data (the response headers from stackoverflow.com) except for <code>/api/test5</code> which never completes.</p>
  
  <h1>Have I encountered a bug in the HttpClient class, or am I misusing the API in some way?</h1>
  
  <p><strong>Code to reproduce:</strong></p>
  
  <pre><code>public class BaseApiController : ApiController
  {
      /// &lt;summary&gt;
      /// Retrieves data using continuations
      /// &lt;/summary&gt;
      protected Task&lt;string&gt; Continuations_GetSomeDataAsync()
      {
          var httpClient = new HttpClient();
  
          var t = httpClient.GetAsync("http://stackoverflow.com", HttpCompletionOption.ResponseHeadersRead);
  
          return t.ContinueWith(t1 =&gt; t1.Result.Content.Headers.ToString());
      }
  
      /// &lt;summary&gt;
      /// Retrieves data using async/await
      /// &lt;/summary&gt;
      protected async Task&lt;string&gt; AsyncAwait_GetSomeDataAsync()
      {
          var httpClient = new HttpClient();
  
          var result = await httpClient.GetAsync("http://stackoverflow.com", HttpCompletionOption.ResponseHeadersRead);
  
          return result.Content.Headers.ToString();
      }
  }
  
  public class Test1Controller : BaseApiController
  {
      /// &lt;summary&gt;
      /// Handles task using Async/Await
      /// &lt;/summary&gt;
      public async Task&lt;string&gt; Get()
      {
          var data = await Continuations_GetSomeDataAsync();
  
          return data;
      }
  }
  
  public class Test2Controller : BaseApiController
  {
      /// &lt;summary&gt;
      /// Handles task by blocking the thread until the task completes
      /// &lt;/summary&gt;
      public string Get()
      {
          var task = Continuations_GetSomeDataAsync();
  
          var data = task.GetAwaiter().GetResult();
  
          return data;
      }
  }
  
  public class Test3Controller : BaseApiController
  {
      /// &lt;summary&gt;
      /// Passes the task back to the controller host
      /// &lt;/summary&gt;
      public Task&lt;string&gt; Get()
      {
          return Continuations_GetSomeDataAsync();
      }
  }
  
  public class Test4Controller : BaseApiController
  {
      /// &lt;summary&gt;
      /// Handles task using Async/Await
      /// &lt;/summary&gt;
      public async Task&lt;string&gt; Get()
      {
          var data = await AsyncAwait_GetSomeDataAsync();
  
          return data;
      }
  }
  
  public class Test5Controller : BaseApiController
  {
      /// &lt;summary&gt;
      /// Handles task by blocking the thread until the task completes
      /// &lt;/summary&gt;
      public string Get()
      {
          var task = AsyncAwait_GetSomeDataAsync();
  
          var data = task.GetAwaiter().GetResult();
  
          return data;
      }
  }
  
  public class Test6Controller : BaseApiController
  {
      /// &lt;summary&gt;
      /// Passes the task back to the controller host
      /// &lt;/summary&gt;
      public Task&lt;string&gt; Get()
      {
          return AsyncAwait_GetSomeDataAsync();
      }
  }
  </code></pre>