Azure Storage Calculated MD5 does not match existing property

I was able to recreate the problem you're facing. This happens if the Content MD5 property of the blob is somehow corrupted. I had a blob with some content MD5 (which was correct). I then programmatically changed the MD5 to some other value (which is incorrect). Now when I call DownloadToStream() method on the blob, I get exact same error.

You can bypass this check by setting DisableContentMD5Validation to true in BlobRequestOptions as shown in the code below:

            BlobRequestOptions options = new BlobRequestOptions()
            {
                DisableContentMD5Validation = true,
            };
            blockBlob.DownloadToStream(memoryStream, null, options);

Give it a try and it should work.

On a side note, you may want to modify your ReadFully method as well. You would need to move the input stream pointer to the beginning.

    public static byte[] ReadFully(Stream input)
    {
        input.Position = 0;//Positioning it to the top of stream.
        using (MemoryStream ms = new MemoryStream())
        {
            input.CopyTo(ms);
            return ms.ToArray();
        }
    }

I had this problem on my local DEV environment. And it seems that db of AzureStorageEmulator got corrupted.

The solution (for local env!):

  • drop the emulator's db (e.g. AzureStorageEmulatorDb57)
  • run AzureStorageEmulator.exe init -sqlinstance . (you may need to customize the instance name)
  • run AzureStorageEmulator.exe start
  • restart the application, so it gets a new handler to the emulator