title: Change overridden member to async
body: <p>I am overriding a method in a base class library.  However, inside my overridden implementation I am using the new HttpClient which is all based on async methods.  I therefore have to mark my method as async, which means that I need to change the return parameter of the method from string to Task.  The compiler however gives an error: "The return type must be 'string' to match overridden member ...."</p>
  
  <pre><code>    public class BaseClass
      {
          public virtual string GetName()
          {
              ...
          }
      }
  
      public class MyClass : BaseClass
      {
          public override async Task&lt;string&gt; GetName()
          {
              HttpClient httpClient = new HttpClient();
              var response = await httpClient.GetAsync("");
              if (response.IsSuccessStatusCode)
              {
                  var responseContent = response.Content;
  
                  return await responseContent.ReadAsStringAsync();
              }
  
              return null;
          }
      }
  </code></pre>
  
  <p>Of course the obvious solution would be to change the return type of GetName() in BaseClass to Task&lt;string&gt;, but I have no control over BaseClass as it is an external library;</p>
  
  <p>My current solution is to use the HttpClient classes in a synchronous fashion, i.e. change MyClass as follows:</p>
  
  <pre><code>    public class MyClass : BaseClass
      {
          public override string GetName()
          {
              HttpClient httpClient = new HttpClient();
              var response = httpClient.GetAsync("");
              if (response.Result.IsSuccessStatusCode)
              {
                  var responseContent = response.Result.Content;
  
                  return responseContent.ReadAsStringAsync()
                                                         .Result;
              }
  
              return null;
          }
      }
  </code></pre>
  
  <p>Is there any other way to do this?</p>