title: Bug when using await/async for System.Net.Http with .NET Core (.NET Standard 1.4 and .NET Framework 4.6.1)?
body: <p>Foreground: I was investigating a bug in an ASP.NET Core project (targeting .NET 4.6.1, using assemblies from .Net Standard 1.4), that threw a MissingMethodException, although this in no way could be possible. Isolating the faulting method, I took the core of the code out to a separate unit test which also targets .NET 4.6.1.</p>
  
  <p>The exception I receive, <code>ThreadAbortException</code>, from the unit test is more or less this (it sometime various): </p>
  
  <pre><code>   at System.Net.Http.WinHttpHandler.SetRequestHandleDecompressionOptions(SafeWinHttpHandle requestHandle)
     at System.Net.Http.WinHttpHandler.SetRequestHandleOptions(WinHttpRequestState state)
     at System.Net.Http.WinHttpHandler.&lt;StartRequest&gt;d__103.MoveNext()
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Net.Http.HttpClient.&lt;FinishSendAsync&gt;d__58.MoveNext()
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Hub.Test.UnitTest1.&lt;FetchUrlAsync&gt;d__2.MoveNext() 
  </code></pre>
  
  <p>The code in question for the abolve exception:</p>
  
  <pre><code>[TestClass]
  public class UnitTest1
  {
      [TestMethod]
      public void TestMethod1()
      {
          //FetchUrl(); // works
          var task = FetchUrlAsync(); // does not work
      }
  
      private void FetchUrl()
      {
          var handler = new HttpClientHandler();
          handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
          using (var client = new HttpClient(handler, true))
          {
              var response = client.SendAsync(new HttpRequestMessage(HttpMethod.Get, new Uri("https://github.com/dotnet/core"))).Result;
              Trace.WriteLine("FetchUrl:" + response.StatusCode);
          }
      }
  
      private async Task FetchUrlAsync()
      {
          try
          {
              var handler = new HttpClientHandler();
              handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
              using (var client = new HttpClient(handler, true))
              {
                  var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, new Uri("https://github.com/dotnet/core")));
                  Trace.WriteLine("FetchUrlAsync: " + response.StatusCode);
              }
          }
          catch (Exception e)
          {
              Trace.WriteLine(e);
              throw;
          }
      }
  }
  </code></pre>
  
  <p>Notice, that if I call FetchUrl() the code works. Yes, I know this became a sync method the moment i invoked result, but it is for demonstration purpose only.</p>
  
  <p>However, the faulting method, FetchUrlAsync(), keeps throwing a ThreadAbortException.</p>
  
  <p>Reason for SendAsync is, that the original implementation is a generic one using this one method for all the Http* work. The same error can be triggered with GetAsync and so forth.</p>
  
  <p>I cannot figure out what I am doing wrong here, but I suspect this error to be a bug somewhere in the .NET CLR.</p>
  
  <p>UPDATE</p>
  
  <p>Although the unit test problem was solved (thank you), I still experienced issue in the ASP.NET Core web-api. From my understanding, .NET Standard 1.4 and .NET Framework 4.6.1 should be 1-1 compatible. This is why i believe there is a rare bug in the framework, although it seems unlikely.</p>
  
  <p>The common denominator is System.Net.Http; and this varies bitwise from .NET Standard 1.4 and .NET Framework 4.6.1; and I tend to find out what the problem is and post the answer to others that might struggle with a similar problem.</p>