Aspnetcore: Missing field CalculateMd5ForResponseStream for DataProtection

Created on 7 Apr 2020  路  8Comments  路  Source: dotnet/aspnetcore

Hello,

We are upgrading one of our web apps from .Net Core 2.2 to 3.1 and with that all the packages. Right now we are having problems with our configuration of DataProtection using Azure blob storage. We are using the following version of the package and configuration code:

Microsoft.AspNetCore.DataProtection.AzureStorage 3.1.3

public static void UseAzureDataProtection(this IServiceCollection services, DataProtectionSettings settings)
{
    var credentials = new StorageCredentials(settings.AccountName, settings.AccountKey);
    var cloudStorageAccount = new CloudStorageAccount(credentials, true);
    var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
    var container = cloudBlobClient.GetContainerReference($"{settings.ApplicationName}-container");

    container.CreateIfNotExistsAsync().GetAwaiter().GetResult();

    services.AddDataProtection().PersistKeysToAzureBlobStorage(container, $"{settings.ApplicationName}-keys.xml");
}

Which throws the following error in the requests pipeline:

An error occurred while reading the key ring.
System.MissingFieldException: Field not found: 'Microsoft.Azure.Storage.Core.Executor.RESTCommand`1.CalculateMd5ForResponseStream'.
   at Microsoft.Azure.Storage.Blob.CloudBlob.GetBlobImpl(BlobAttributes blobAttributes, Stream destStream, Nullable`1 offset, Nullable`1 length, AccessCondition accessCondition, BlobRequestOptions options)
   at Microsoft.Azure.Storage.Blob.CloudBlob.DownloadRangeToStreamAsync(Stream target, Nullable`1 offset, Nullable`1 length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext, AggregatingProgressIncrementer progressIncrementer, CancellationToken cancellationToken)
   at Microsoft.Azure.Storage.Blob.CloudBlob.DownloadToStreamAsync(Stream target, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
   at Microsoft.AspNetCore.DataProtection.AzureStorage.AzureBlobXmlRepository.GetLatestDataAsync(ICloudBlob blobRef)
   at Microsoft.AspNetCore.DataProtection.AzureStorage.AzureBlobXmlRepository.GetAllElementsAsync(ICloudBlob blobRef)
   at Microsoft.AspNetCore.DataProtection.AzureStorage.AzureBlobXmlRepository.GetAllElements()
   at Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.GetAllKeys()
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.CreateCacheableKeyRingCore(DateTimeOffset now, IKey keyJustAdded)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.ICacheableKeyRingProvider.GetCacheableKeyRing(DateTimeOffset now)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRingCore(DateTime utcNow, Boolean forceRefresh)

If we downgrade the package to the 2.2.7 version, with the same configuration code it works. The only thing is that we also need to update the using's since they were changed from Microsoft.WindowsAzure.Storage on 2.x.x to Microsoft.Azure.Storage on 3.x.x.

In addition, I can see in the following commit that the field was removed, I just don't know why it's still trying to use it: https://github.com/Azure/azure-storage-net/commit/38f703c3d4d94f09f65b2b2f92f4f837d402fc42#diff-6d37e66772ae1b6ed4d77c52778c9336

area-dataprotection

Most helpful comment

It's a couple of months later and I ran into this issue today. The solution that worked for me was to update both packages Microsoft.Azure.Storage.Common and Microsoft.Azure.Storage.Blob from 10.0.3 to 11.1.7.

What was strange to me was that this was a production deployed Function App that suddenly stopped working.

Edit- It turns out the Functions runtime was updated to version 2.0.13759.0 which was the reason that our app stopped working suddenly. Release announcements are documented here https://github.com/Azure/app-service-announcements/issues

All 8 comments

cc @pakrym

I also get this error, I'm trying to store the keys for the first time just following this excact example: Key storage providers - Azure

..
var container = client.GetContainerReference("my-key-container");
..
.PersistKeysToAzureBlobStorage(container, "keys.xml")

my-key-container is created so the connection is working
I even tried uploading the keys.xml created before turning on this feature

I did not try any form of encryption

fail: Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider[48]
      An error occurred while reading the key ring.
System.MissingFieldException: Field not found: 'Microsoft.Azure.Storage.Core.Executor.RESTCommand`1.CalculateMd5ForResponseStream'.
   at Microsoft.Azure.Storage.Blob.CloudBlob.GetBlobImpl(BlobAttributes blobAttributes, Stream destStream, Nullable`1 offset, Nullable`1 length, AccessCondition accessCondition, BlobRequestOptions options)
   at Microsoft.Azure.Storage.Blob.CloudBlob.DownloadRangeToStreamAsync(Stream target, Nullable`1 offset, Nullable`1 length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext, AggregatingProgressIncrementer progressIncrementer, CancellationToken cancellationToken)
   at Microsoft.Azure.Storage.Blob.CloudBlob.DownloadToStreamAsync(Stream target, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
   at Microsoft.AspNetCore.DataProtection.AzureStorage.AzureBlobXmlRepository.GetLatestDataAsync(ICloudBlob blobRef)
   at Microsoft.AspNetCore.DataProtection.AzureStorage.AzureBlobXmlRepository.GetAllElementsAsync(ICloudBlob blobRef)
   at Microsoft.AspNetCore.DataProtection.AzureStorage.AzureBlobXmlRepository.GetAllElements()
   at Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.GetAllKeys()
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.CreateCacheableKeyRingCore(DateTimeOffset now, IKey keyJustAdded)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.ICacheableKeyRingProvider.GetCacheableKeyRing(DateTimeOffset now)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRingCore(DateTime utcNow, Boolean forceRefresh)

I got the same issue with the following packages.

    <PackageReference Include="Microsoft.AspNetCore.DataProtection.AzureKeyVault" Version="3.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.DataProtection.AzureStorage" Version="3.1.3" />
    <PackageReference Include="Microsoft.Azure.Storage.Common" Version="11.1.3" />

After I downgrade Microsoft.Azure.Storage.Common package to 10.0.3. it works!

    <PackageReference Include="Microsoft.Azure.Storage.Common" Version="10.0.3" />

We ran into this and unfortunately didn't find the mitigation's worked.

It's a couple of months later and I ran into this issue today. The solution that worked for me was to update both packages Microsoft.Azure.Storage.Common and Microsoft.Azure.Storage.Blob from 10.0.3 to 11.1.7.

What was strange to me was that this was a production deployed Function App that suddenly stopped working.

Edit- It turns out the Functions runtime was updated to version 2.0.13759.0 which was the reason that our app stopped working suddenly. Release announcements are documented here https://github.com/Azure/app-service-announcements/issues

@pdl5p - We had the same issue that also started 2 days ago. Same fix for us also. Thanks for the insight.

Thanks @pdl5p , had the same issue with a production Azure function that's been running for months that stopped working a couple of days ago. Updated packages as noted in the comment above and works fine now.

Closing as there is no further action pending here. This seems to have been caused by using legacy Azure Storage packages.

Was this page helpful?
0 / 5 - 0 ratings