C# Azure文件共享下载erorr';未找到字段:';Microsoft.Azure.Storage.Core.Executor.RESTCommand`1.CalculateMd5ForResponseStream'';

C# Azure文件共享下载erorr';未找到字段:';Microsoft.Azure.Storage.Core.Executor.RESTCommand`1.CalculateMd5ForResponseStream'';,c#,azure,C#,Azure,我正在尝试从Azure文件共享下载文件。当我尝试下载流时,我得到错误“未找到”字段:“Microsoft.Azure.Storage.Core.Executor.RESTCommand`1.CalculateMd5ForResponseStream.” 这是我的密码。我做错了什么 [TestMethod] public void GetFileFromAzureShare() { string connectionstring = @"...";

我正在尝试从Azure文件共享下载文件。当我尝试下载流时,我得到错误“未找到”字段:“Microsoft.Azure.Storage.Core.Executor.RESTCommand`1.CalculateMd5ForResponseStream.” 这是我的密码。我做错了什么

 [TestMethod]
    public void GetFileFromAzureShare()
    {
        string connectionstring = @"...";
        //
        FSAzureFileShareStorage storage = new FSAzureFileShareStorage(connectionstring, "sftpfileshare");
        var s = storage.GetStream("OLD/Testfile_ignore.txt").Result;
        var text = new System.IO.StreamReader(s).ReadToEnd();

    }

public class FSAzureFileShareStorage 
{
    private readonly CloudFileShare _share;

    public FSAzureFileShareStorage(string connectionString, string shareName)
    {
        try
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
            CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
            _share = fileClient.GetShareReference(shareName);
            AccountConnected = _share != null;
        }
        catch (Exception ex)
        {
            LastException = ex;
            AccountConnected = false;
        }
    }
      public async Task<Stream> GetStream(string filePath)
    {
        Stream rtn = null;
        try
        {
            if (_share.Exists())
            {
                var root = _share.GetRootDirectoryReference();
                var fileRef = root.GetFileReference(filePath);
                if (fileRef != null)
                {
                    rtn = await fileRef.OpenReadAsync();
                }
            }
        }
        catch (Exception ex)
        {
            LastException = ex;
        }
        return rtn;
    }
}
[TestMethod]
public void GetFileFromAzureShare()
{
字符串连接字符串=@“…”;
//
FSAzureFileShareStorage存储=新的FSAzureFileShareStorage(connectionstring,“sftpfilesharestorage”);
var s=storage.GetStream(“OLD/Testfile_ignore.txt”).Result;
var text=new System.IO.StreamReader.ReadToEnd();
}
公共类FSAzureFileShareStorage
{
私有只读云文件共享;
公共FSAzureFileShareStorage(字符串连接字符串、字符串共享名)
{
尝试
{
CloudStorageAccount-storageAccount=CloudStorageAccount.Parse(connectionString);
CloudFileClient fileClient=storageAccount.CreateCloudFileClient();
_share=fileClient.GetShareReference(shareName);
AccountConnected=\u share!=null;
}
捕获(例外情况除外)
{
LastException=ex;
AccountConnected=false;
}
}
公共异步任务GetStream(字符串文件路径)
{
流rtn=null;
尝试
{
如果(_share.Exists())
{
var root=\u share.GetRootDirectoryReference();
var fileRef=root.GetFileReference(filePath);
如果(fileRef!=null)
{
rtn=await fileRef.OpenReadAsync();
}
}
}
捕获(例外情况除外)
{
LastException=ex;
}
返回rtn;
}
}

根据我的测试,如果我们想从Azure文件共享下载文件,我们可以使用以下代码:

/*
  install following sdk
  Install-Package Microsoft.Azure.Storage.File -Version 11.1.1
  Install-Package Microsoft.Azure.Storage.Common -Version 11.1.1 

*/

 var connectionString = "";
            var filepath = @"D:\download\";
            var shareName = "test";
            var storageAccount = CloudStorageAccount.Parse(connectionString);
            var fileClient = storageAccount.CreateCloudFileClient();
            var fileshare = fileClient.GetShareReference(shareName);
            if ( fileshare.Exists()) {

                var root = fileshare.GetRootDirectoryReference();
                var file = root.GetFileReference("keyCredentials.txt");
                if (file.Exists()) {
                    filepath = filepath + file.Name;
                    using (var stream = File.OpenWrite(filepath))
                    {

                        file.DownloadToStream(stream);

                    }



                }

            }

把它弄明白了。我的Microsoft.Azure.Storage.DataMovement版本错误。已将此升级到当前版本,问题已修复

既然你的问题已经由你自己解决了,你能接受这个答案吗?它可能会帮助更多有类似问题的人。