c# - Azure Storage Queue.AddMessageAsync(item,cancelToken) 缺少接受两个参数的方法

标签 c# azure .net-core azure-storage

我正在尝试执行以下无法编译的代码:

var message = new CloudQueueMessage(item);
return queue.AddMessageAsync(message, cancellationToken);

编译器表示不存在只接受 2x 参数的方法。

The offical MS documentation应该有一个接受2x参数的方法。

The official code on GitHub还表明应该有一个接受 2x 参数的方法...

我通过 NuGet 使用 Assembly Microsoft.WindowsAzure.Storage, Version=9.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 ,其中仅列出了以下 3 种方法:

public virtual Task AddMessageAsync(CloudQueueMessage message);
public virtual Task AddMessageAsync(CloudQueueMessage message, TimeSpan? timeToLive, TimeSpan? initialVisibilityDelay, QueueRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken);
public virtual Task AddMessageAsync(CloudQueueMessage message, TimeSpan? timeToLive, TimeSpan? initialVisibilityDelay, QueueRequestOptions options, OperationContext operationContext);

有人可以解释一下吗:

  1. 这些文档是否已经过时?
  2. 文档很好,但适用于较新版本的 Azure 存储 NuGet 包?
  3. 如果它不在 v 9.3 NuGet 包中,那么我应该如何正确地将 CancellationToken 传递给该方法?为每个参数传递null

这是针对 .NET Core 项目的。

最佳答案

.NET Framework 和 .NET Core 的存储 SDK 存在细微差别,文档中未对此进行说明。

从 v9.2.0 开始,.NET Core SDK 中已删除 AddMessageAsync(CloudQueueMessage message, CancellationToken CancellationToken) 方法。因此,一种解决方法是将 sdk 降级到 v9.1.1。

好消息是,这些差异将在下一版本的 Azure 存储包中消除。查看相关issue comment .

This library is set to target .NET Standard 2.0 and will not contain these minor API differences.

因此另一个解决方法是使用 preview version在它普遍可用之前。

请注意,预览版本中的命名空间已更改。

using Microsoft.Azure.Storage; 
using Microsoft.Azure.Storage.Queue; 

关于c# - Azure Storage Queue.AddMessageAsync(item,cancelToken) 缺少接受两个参数的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51694834/

相关文章:

c# - 如何创建一个一次只能从一个线程执行的异步方法?

c# - 在列表中查找对象并替换其值

azure - 使用 NuGet 安装 Windows Azure Storage v3.0.3 失败

c# - dotnetcore 控制台上的 Microsoft.Extensions.Logging 和 Serilog。在 RollingFile 接收器中包含范围信息

c# - 将通用预加载方法从 EF6 转换为 EF Core

.net - 适用于centos 7的Docker设置

c# - 在列表中查找两个(或更多)属性的最大值

azure - 从函数应用程序中运行 New-AzureRmResourceGroupDeployment

asp.net - vs2013 azure web 部署失败并显示未知的 ProviderOption :DefiningProjectFullPath

c# - Datagridview 上下文菜单总是在 hittest 中显示 -1