【问题标题】:Azure Storage Queue.AddMessageAsync(item, cancellationToken) is missing the method which accepts two argumentsAzure Storage Queue.AddMessageAsync(item, cancelToken) 缺少接受两个参数的方法
【发布时间】:2019-06-17 00:22:13
【问题描述】:

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

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 core 的吗?
  • 是的。对不起。将更新 OP。

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


【解决方案1】:

.NET Framework 和 .NET Core 的存储 SDK 存在细微差别,文档中没有说明。

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

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

此库设置为面向 .NET Standard 2.0,不会包含这些细微的 API 差异。

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

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

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

【讨论】:

    猜你喜欢
    • 2013-10-13
    • 2020-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    • 2014-04-15
    • 2017-01-06
    • 1970-01-01
    相关资源
    最近更新 更多