title: C# How to await a method that returns Task<dynamic>?
body: <p>I have a method that is parsing the results from a JSON object. The method returns a Task object but when I run the code, I am getting the following error:</p>
  
  <pre><code>'System.Collections.Generic.Dictionary&lt;string,object&gt;' does not contain a definition for 'GetAwaiter'
  </code></pre>
  
  <p>The object returned from the dynamic method is an array of objects of type System.Collections.Generic.Dictionary and System.Collections.Generic.KeyValuePair. Here is the code:</p>
  
  <pre><code>private static async Task&lt;dynamic&gt; GetReslutstAsync(string url)
      {
          WebRequest request;
          WebResponse response = null;
          try
          {
              request = WebRequest.Create(url);
              request.Credentials = new NetworkCredential("username", "password", "company");
              //request.Credentials = CredentialCache.DefaultNetworkCredentials;
              response = await request.GetResponseAsync();
          }
          catch (Exception e)
          {
              Console.WriteLine(e.Message);
          }
  
          using (var reader = new StreamReader(response.GetResponseStream()))
          {
              try
              {
                  JavaScriptSerializer js = new JavaScriptSerializer();
                  var objects = js.Deserialize&lt;dynamic&gt;(reader.ReadToEnd());
                  return objects;
              }
              catch (Exception e)
              {
                  Console.WriteLine(e.Message);
                  return null;
              }
          }
      }
  </code></pre>
  
  <p>The exception occurs here:</p>
  
  <pre><code>private static async Task&lt;dynamic&gt; MakeRequest(string url)
      {
          try
          {
              return await GetReslutstAsync(url).Result;  //&lt;---- This is where I get the error!
          }
          catch (Exception e)
          {
              Console.WriteLine(e.Message);
              return null;
          }
      }
  </code></pre>
  
  <p>I believe this has something to do with the fact that I am returning a dynamic type object. How can I get around this? I need to await this task inside the "MakeRequest" method so that it does not continue until the request is completed.</p>
  
  <p>EDIT:  </p>
  
  <p>My "MakeRequest" method is in a loop like this:</p>
  
  <pre><code>while (true)
          {
              ClockTimer timer = new ClockTimer();
              timer.StartTimer(); //&lt;---This does not stop untill 5 sec has passed
              MakeRequest("www.someurl.com"); //&lt;--- This just skips into the next loop even if not complete.
          }
  </code></pre>
  
  <p>My issue is that <code>MakeRequest</code> is being run asynchronously so basically, it just skips over this and goes right into the next loop. I need "MakeRequest"  to HALT until the request is finished. I have tried removing all async/await keywords but this just results in "Result was not calculated".</p>