here is the offending code
public async static Task AsyncReadBlob(string identifier)
{
CloudStorageAccount storageAccount
Short version... Use:
await blockBlob.DownloadToStreamAsync(memstream).ConfigureAwait(false);
Long version:
When you await a task in C#, the task scheduler will try to execute the block of code that comes after the await in the same thread that called the original await.
The problem is that in some cases (can't recall right now the specific circumstances) the ASP.NET Thread Scheduler will block the thread while waiting for the Task to return. When the task returns, the task blocks waiting for the original thread to be released, while the thread is blocked waiting for the task to end. So you end deadlocked.
ConfigureAwait allows you to deactivate that behavior.