问题
I'm using a precompiled Azure Function that looks:
public static async Task Run(Stream inputBlob, Stream outputJson, Stream outputXml, CloudTable schedulerTable)
The output binding looks:
{
"name": "schedulerTable",
"type": "table",
"direction": "out",
"tableName": "SchedulerTable",
"connection": "SchedulerTable"
}
When i remove the parameter schedulerTable from my function, it's works. ´The message that the host throws in my face is:
Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.InputFileAdaptorAF'. Microsoft.Azure.WebJobs.Host: Can't bind Table to type 'Microsoft.WindowsAzure.Storage.Table.CloudTable'.
Really, when i add a table output binding trying with diferent alternatives, nothing works. Alternatives that doesn't work are:
- Parameter schedulerTable with type SchedulerRegister. The class SchedulerRegister inherits from TableEntity.
- Parameter schedulerTable with type ICollector.
- Parameter schedulerTable with type CloudTable. (the case above).
Please, ¿How I can fix it? (Use an output binding to azure table)
回答1:
You're likely running into type mismatch issues. What version of the storage SDK are you using? You need to make sure storage SDK references match what the runtime expects, which currently is 7.2.1.
Please make sure that you're referencing the storage SDK version 7.2.1.
回答2:
According to your description, I have tested this issue about binding to the table output, I could make it work as expected. Here is my code snippet, you could refer to it.
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<T>
#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.WindowsAzure.Storage.Blob;
public static void Run(CloudBlockBlob inputBlob, ICollector<UploadFile> 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; }
}
Modify your code and click Save, if the compilation executes successfully, then when the function is triggered, you could see the following log and the record is added to Azure Table Storage.
For more details, you could refer to this official document about storage table binding for Azure function.
回答3:
Really, this answer is from someone (i don't remember de name) in the team of Azure Functions, here in this question, but he delete her response. He says that surely the problem is from having diferent version of the dll that expected. I can confirm that these was the problem.
The solution is to check the version of dlls used in AppData\Local\Azure.Functions.Cli\1.0.0-beta.91 and use the same in the solution.
来源:https://stackoverflow.com/questions/42284705/precompiled-azure-function-and-cloudtable-binding-output-doesnt-work