我有一个事件函数,它应该返回 IEnumerable<IListBlobItem>
如下:
[FunctionName("process_file_GetBlobList")]
public static IEnumerable<IListBlobItem> GetBlobList([ActivityTrigger] string name, ILogger log)
{
string storageConnectionString = @"connstring";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("container");
IEnumerable<IListBlobItem> blobs = new IListBlobItem[0];
foreach (IListBlobItem blobItem in container.ListBlobs())
{
if (blobItem is CloudBlobDirectory)
{
CloudBlobDirectory directory = (CloudBlobDirectory)blobItem;
blobs = directory.ListBlobs(true);
}
}
return blobs;
}
在我的 Orchestrator 中,我按如下方式调用此事件函数:
IEnumerable<IListBlobItem> blobs = await context.CallActivityAsync<IEnumerable<IListBlobItem>>("process_file_GetBlobList", null);
通过调试,我没有收到错误消息,但在运行时我收到此消息:
failed: Could not create an instance of type Microsoft.Azure.Storage.Blob.IListBlobItem. Type is an interface or abstract class and cannot be instantiated. Path '[0].StreamWriteSizeInBytes'
有任何想法吗,我如何通过 CallActivityAsync
调用我的事件函数?
最佳答案
将其更改为列表并查看,
List<ListBlobItem> blobs = await context.CallActivityAsync<List<ListBlobItem>>("process_file_GetBlobList", null);
但是,您可以通过将 blob 更改为 var 类型来修复上述错误。
关于c# - Activity 函数应返回 IEnumerable<IListBlobItem>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58780228/