title: CloudBlob.DownloadToStream returns null
body: <p>I'm trying to download a file from cloudBlob via stream. I refer to this article <a href="http://jeanpaulva.com/category/azure/" rel="noreferrer">CloudBlob</a>  </p>
  
  <p>Here is the code to download the blob  </p>
  
  <pre><code>public Stream DownloadBlobAsStream(CloudStorageAccount account, string blobUri)
  {
      Stream mem = new MemoryStream();
      CloudBlobClient blobclient = account.CreateCloudBlobClient();
      CloudBlockBlob blob = blobclient.GetBlockBlobReference(blobUri);
  
      if (blob != null)
          blob.DownloadToStream(mem);
  
      return mem;
  }  
  </code></pre>
  
  <p>And the code to convert it into byte array  </p>
  
  <pre><code>    public static byte[] ReadFully(Stream input)
      {
          byte[] buffer = new byte[16 * 1024];
          using (MemoryStream ms = new MemoryStream())
          {
              int read;
              while ((read = input.Read(buffer, 0, buffer.Length)) &gt; 0)
              {
                  ms.Write(buffer, 0, read);
              }
              return ms.ToArray();
          }
      }  
  </code></pre>
  
  <p>But I always get null value. Below is the content of the streamed file.  </p>
  
  <p><img src="https://i.stack.imgur.com/rwKHx.png" alt="enter image description here">  </p>
  
  <p>What is wrong with this? Please help.</p>
  
  <p><strong>EDIT</strong>  </p>
  
  <p>Setting the Position to 0 inside <code>ReadFully</code> method is not allowed, so I put it inside <code>DownloadBlobAsStream</code>  </p>
  
  <p>This should work now:  </p>
  
  <pre><code>public Stream DownloadBlobAsStream(CloudStorageAccount account, string blobUri)
  {
      Stream mem = new MemoryStream();
      CloudBlobClient blobclient = account.CreateCloudBlobClient();
      CloudBlockBlob blob = blobclient.GetBlockBlobReference(blobUri);
  
      if (blob != null)
          blob.DownloadToStream(mem);
      mem.Position = 0;   
      return mem;
  } 
  </code></pre>