我在做什么错?您如何指定多个属性?
我试图像这样动态地注册到输出Blob的绑定:
var attributes = new Attribute[]
{
new BlobAttribute("success/{CorrelationId}"),
new StorageAccountAttribute("MyStorageAccount")
};
using (var writer = await binder.BindAsync<TextWriter>(attributes))
{
writer.Write(JsonConvert.SerializeObject(myQueueItem.Body));
}
我遇到以下异常:
这是完整的代码:
public static class OnSchedulingToMMMQueueTriggered
{
[FunctionName("OnSchedulingToMMMQueueTriggered")]
public static async System.Threading.Tasks.Task RunAsync(
[QueueTrigger("httpqueue", Connection = "OnSchedulingToMMMQueueTriggered:SourceQueueConnection")] Payload myQueueItem,
[Blob("processed/{CorrelationId}", FileAccess.Write, Connection = "OnSchedulingToMMMQueueTriggered:ProcessedPayloadsConnectionString")] Stream processedPayload,
IBinder binder,
ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem.Body}");
var attributes = new Attribute[]
{
new BlobAttribute("success/{CorrelationId}"),
new StorageAccountAttribute("MyStorageAccount")
};
using (var writer = await binder.BindAsync<TextWriter>(attributes))
{
writer.Write(JsonConvert.SerializeObject(myQueueItem.Body));
}
}
}
我在做什么错?您如何指定多个属性?
答案 0 :(得分:1)
文档确实说如果要使用多个,则应使用Binder
类而不是IBinder
接口。
使用
Binder
参数,而不使用IBinder
例如
public static class OnSchedulingToMMMQueueTriggered {
[FunctionName("OnSchedulingToMMMQueueTriggered")]
public static async Task RunAsync(
[QueueTrigger("httpqueue", Connection = "OnSchedulingToMMMQueueTriggered:SourceQueueConnection")] Payload myQueueItem,
[Blob("processed/{CorrelationId}", FileAccess.Write, Connection = "OnSchedulingToMMMQueueTriggered:ProcessedPayloadsConnectionString")] Stream processedPayload,
Binder binder, //<--NOTE *Binder* not *IBinder*
ILogger log) {
log.LogInformation($"C# Queue trigger function processed: {myQueueItem.Body}");
var attributes = new Attribute[] {
new BlobAttribute("success/{CorrelationId}"),
new StorageAccountAttribute("MyStorageAccount")
};
using (var writer = await binder.BindAsync<TextWriter>(attributes)) {
writer.Write(JsonConvert.SerializeObject(myQueueItem.Body));
}
}
}