预编译的Azurefunction和CloudTable绑定输出不起作用

我正在使用预编译的Azure函数,它看起来像:

public static async Task Run(Stream inputBlob, Stream outputJson, Stream outputXml, CloudTable schedulerTable) 

输出绑定看起来:

 { "name": "schedulerTable", "type": "table", "direction": "out", "tableName": "SchedulerTable", "connection": "SchedulerTable" } 

当我从我的函数中删除参数schedulerTable时,它是有效的。 “主持人扔在我脸上的信息是:

 Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.InputFileAdaptorAF'. Microsoft.Azure.WebJobs.Host: Can't bind Table to type 'Microsoft.WindowsAzure.Storage.Table.CloudTable'. 

真的,当我添加一个表输出绑定尝试使用不同的替代品时,没有任何作用。 不起作用的替代方案是:

  • 参数schedulerTable,类型为SchedulerRegister。 SchedulerRegister类inheritance自TableEntity。
  • 带有ICollector类型的参数schedulerTable。
  • 参数schedulerTable,类型为CloudTable。 (上述情况)。

拜托,我怎么能解决它? (使用输出绑定到azure表)

您可能遇到类型不匹配问题。 您使用的是哪个版本的存储SDK? 您需要确保存储SDK引用与运行时期望的内容相匹配,当前为7.2.1。

请确保您引用的是存储SDK版本7.2.1。

根据你的描述,我已经测试了关于绑定到表输出的这个问题,我可以使它按预期工作。 这是我的代码片段,你可以参考它。

function.json

 { "bindings": [ { "name": "inputBlob", "type": "blobTrigger", "direction": "in", "path": "input/{name}", "connection": "AzureStorageConnectionString" }, { "type": "table", "name": "outTable", "tableName": "UploadFile", "connection": "AzureStorageConnectionString", "direction": "out" } ], "disabled": false } 
  • ICollector
 #r "Microsoft.WindowsAzure.Storage" using Microsoft.WindowsAzure.Storage.Table; using Microsoft.WindowsAzure.Storage.Blob; public static void Run(CloudBlockBlob inputBlob, ICollector outTable, TraceWriter log) { string blobUri=inputBlob.StorageUri.PrimaryUri.ToString(); log.Info($"C# Blob trigger function triggered, blob path: {blobUri}"); outTable.Add(new UploadFile() { PartitionKey = "Functions", RowKey = Guid.NewGuid().ToString(), Name = blobUri }); } public class UploadFile : TableEntity { public string Name { get; set; } } 
  • CloudTable
 #r "Microsoft.WindowsAzure.Storage" using Microsoft.WindowsAzure.Storage.Table; using Microsoft.WindowsAzure.Storage.Blob; public static void Run(CloudBlockBlob inputBlob,CloudTable outTable, TraceWriter log) { string blobUri=inputBlob.StorageUri.PrimaryUri.ToString(); log.Info($"C# Blob trigger function triggered, blob path: {blobUri}"); outTable.Execute(TableOperation.Insert(new UploadFile() { PartitionKey = "Functions", RowKey = Guid.NewGuid().ToString(), Name = blobUri })); } public class UploadFile : TableEntity { public string Name { get; set; } } 

修改代码并单击“ 保存” ,如果编译成功执行,则在触发该function时,您可以看到以下日志,并将该记录添加到Azure表存储。

有关更多详细信息,请参阅此官方文档,了解Azurefunction的存储表绑定。

实际上,这个答案来自Azure Functions的团队中的某个人(我不记得de name),在这个问题中,但是他删除了她的回复。 他说,问题肯定来自于预期的dll版本不同。 我可以确认这是问题所在。

解决方案是检查AppData \ Local \ Azure.Functions.Cli \ 1.0.0-beta.91中使用的dll版本,并在解决方案中使用相同的版本。