如何解决这两个名称空间之间的冲突?

How do I resolve conflicts between these two namespaces?

在我的代码中,我同时使用了这两个命名空间并且一切正常,直到我尝试使用两者中都存在的 CopyStatus。这段代码在具有完全相同命名空间的 LINQPad5 中工作得很好,但是在 VS2019 中,我发现它无法在 Storage.File class 中处理 CopyState。

using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.File;

来自 LINQPad5 的代码

CloudFile file = share.GetRootDirectoryReference().GetFileReference(myfile);

string blobSas = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
{
    Permissions = SharedAccessBlobPermissions.Read,
    SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24)
});
Uri blobSasUri = new Uri(blob.StorageUri.PrimaryUri.ToString() + blobSas);
file.StartCopy(blobSasUri);
file.FetchAttributes();

int count=0;
while (file.CopyState.Status != Microsoft.WindowsAzure.Storage.File.CopyStatus.Success)
{
    Thread.Sleep(1000);
    Console.WriteLine(@"{0} - Sleep one second", count++.ToString());
    file.FetchAttributes();
}

但是这个(几乎)相同的代码在 VS2109 中不起作用。

file.StartCopy(bpe.BlobUri);
file.FetchAttributes();
while (file.CopyState.Status != Microsoft.WindowsAzure.Storage.File.CopyStatus.Success)

图片显示 Microsoft.WindowsAzure.Storage.File.CopyStatus 没有 存在。

这个问题可能主要是由于 VS 2019 缺少 nugget 造成的,我建议安装最新的 WindowsAzure.storage Nugget found here 重新启动 VS,然后重试。

解决方案是升级到 .NET Framework 4.7.2 并在 NuGet 中安装 Microsoft.WindowsAzure.Storage.DataMovement 而不是 Microsoft.WindowsAzure.Storage。

然后限定 using 语句:

using AF=Microsoft.WindowsAzure.Storage.File;
using AB=Microsoft.WindowsAzure.Storage.Blob;