更改 CloudQueueMessage 类型会导致异常绑定参数"myQueueItem"。mscorlib:字符串引用未设置为字符串的实例



创建新的QueueTriggerAzure 函数时,我想将string输入切换到CloudQueueMessage

我已将签名更改为:

public async static Task Run([QueueTrigger("%queue-name%", Connection = "AzureStorageConnection")]CloudQueueMessage myQueueItem, TraceWriter log)

我收到以下错误:

8/15/17 12:16:07 AM] Function started (Id=a137d868-1256-4a67-a225-8a95fb0e31fb) [8/15/17 12:16:07 AM] Executing 'TokenRefresh' (Reason='New queue message detected on 'refreshtoken'.', Id=a137d868-1256-4a67-a225-8a95fb0e31fb) [8/15/17 12:16:07 AM] A ScriptHost error has occurred [8/15/17 12:16:07 AM] Exception while executing function: TokenRefresh. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'myQueueItem'. mscorlib: String reference not set to an instance of a String. [8/15/17 12:16:07 AM] Parameter name: s.

函数应用正确弹出项目,然后因为它随后引发快速异常,该队列中的所有项目都会转到病毒队列。我正在使用最新的函数 sdk 和 windows azure sdk nuget 包。

根据您的描述,我在 Azure 门户上检查了此问题。我发现它可以工作,这是我run.csx文件下的代码片段,如下所示:

#r "Microsoft.WindowsAzure.Storage"
using System;
using Microsoft.WindowsAzure.Storage.Queue;
[FunctionName("QueueTriggerCSharp")]
public static void Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")]CloudQueueMessage myQueueItem, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem.AsString}");
}

结果:

2017-08-15T07:35:27.104 函数已启动 (id=0ed03b74-bc9c-408a-9607-55e2942f1d50(

2017-08-15T07:35:27.214C#队列触发器函数已处理:示例队列数据

2017-08-15T07:35:27.214 函数已完成(成功,id=0ed03b74-bc9c-408a-9607-55e2942f1d50,持续时间=108ms(

正如 garth mason 提到的,然后我使用 VS 2017 函数类库在本地检查了它。另外,我发现了一个类似的问题如何使用队列触发器和VS 2017函数类库更改参数类型以及此git问题,您可以参考它们来解决此问题。

事实证明,这是尝试使用Windows.AzureStoragev8.2.1而不是绑定重定向的v7.2.1的结果。由于CloudQueueMessage对象在版本之间不匹配,因此必须使用 Functions 运行时所依赖的依赖项。

由函数 PM 确认: https://twitter.com/lindydonna/status/897333107354869760

还有一个冗长的问题线程,关于他们何时允许其他依赖项版本的状态: https://github.com/Azure/azure-webjobs-sdk-script/issues/992

最新更新