CloudBlobDirectory' 不包含 'ListBlobs' 的定义,并且在 .net core 3.1 升级中没有可访问的扩展方法 'ListBlobs'

CloudBlobDirectory' does not contain a definition for 'ListBlobs' and no accessible extension method 'ListBlobs' in .net core 3.1 upgrade

我正在将 .net45 应用程序升级到 .net core 3.1,我有一段代码如下。

private void GetContainerDirectories(IEnumerable<IListBlobItem> blobList)
        {
            // First list all the actual FILES within
            // the current blob list. No recursion needed:
            foreach (var item in blobList.Where
            ((blobItem, type) => blobItem is CloudBlockBlob))
            {
                var blobFile = item as CloudBlockBlob;
                sb.Add(new Tree { Name = blobFile.Name, Id = blobFile.Name, ParentId = blobFile.Parent.Prefix, Title = Path.GetFileName(blobFile.Name), IsDirectory = false });
            }

            // List all additional subdirectories
            // in the current directory, and call recursively:
            foreach (var item in blobList.Where
            ((blobItem, type) => blobItem is CloudBlobDirectory))
            {
                var directory = item as CloudBlobDirectory;
                sb.Add(new Tree { Name = directory.Prefix, Id = directory.Prefix, ParentId = directory.Parent.Prefix, Title = new DirectoryInfo(directory.Prefix).Name, IsDirectory = true });

                // Call this method recursively to retrieve subdirectories within the current:
                GetContainerDirectories(directory.ListBlobs()); ***////////Here i am getting error***
            }
        }

在最后一行 [GetContainerDirectories(directory.ListBlobs())] 中,我遇到了 ListBlob 错误,我找不到任何有用的解决方案。像这样的错误 -
'CloudBlobDirectory' 不包含 'ListBlobs' 的定义,并且找不到接受类型 'CloudBlobDirectory' 的第一个参数的可访问扩展方法 'ListBlobs'(您是否缺少使用指令或程序集引用?)

有人知道如何解决这个问题吗?非常感谢:)

您使用的WindowsAzure.StorageSDK太旧,.net core不支持此SDK下的同步方式,ListBlobs方式为同步方式

建议您改用最新的SDK:

https://www.nuget.org/packages/Azure.Storage.Blobs/12.8.0

如果不想使用Azure.Storage.BlobsSDK,可以使用WindowsAzure.StorageSDK

下的ListBlobsSegmentedAsync方法

更新:

您可以使用以下代码代替您的原始代码:

    var blobs = directory.ListBlobsSegmentedAsync(false, BlobListingDetails.Metadata, 100, null, null, null).Result.Results;
    GetContainerDirectories(blobs);