title: Azure downloadtostreamasync method hangs
body: <p>here is the offending code</p>
  
  <pre><code>    public async static Task&lt;MemoryStream&gt; AsyncReadBlob(string identifier)
      {
          CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageString);
          CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
          CloudBlobContainer container = blobClient.GetContainerReference(containerName);
          MemoryStream memstream = new MemoryStream();
          CloudBlockBlob blockBlob = container.GetBlockBlobReference(identifier);
          await blockBlob.DownloadToStreamAsync(memstream);
          return memstream;
      }
  </code></pre>
  
  <p>Basically, the code runs completely fine if I replace</p>
  
  <p><code>await blockBlob.DownloadToStreamAsync(memstream)</code></p>
  
  <p>with</p>
  
  <p><code>blockblob.DownloadToStream(memstream)</code></p>
  
  <p>or</p>
  
  <p><code>blockblob.DownloadToStreamAsync(memstream).wait()</code></p>
  
  <p>But the moment I make it asynchronous, the "download to stream" step never completes. I've also tried using DownloadToStreamBegin() and then waiting for it to complete too, but it never finishes, once again.</p>
  
  <p>Is it not working because it's a static method? Or is it because it's memstream is being de-referenced from memory or something??</p>
  
  <p>I'm using asp.net 4.5, all compiles properly, no interpreter errors or exceptions thrown.</p>
  
  <p>Any help would be greatly appreciated</p>