c# - Activity 函数应返回 IEnumerable<IListBlobItem>

标签 c# azure azure-functions ienumerable azure-durable-functions

我有一个事件函数,它应该返回 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/

相关文章:

c# - 如何将没有扩展名的 DICOM 文件转换为 .png 文件或 .jpg 文件?

c# - 为身份验证类型 : Individual User account ASP. NET 核心 2.1、MVC、c# 自定义登录页面设计

linux - 无法启动虚拟机 - Azure 门户错误

azure - Docker 构建失败并出现 "Service failed to build: COPY failed: no such file or directory"错误

c# - 通过 Microsoft Exchange Server 发送电子邮件

c# - 如何在 C# 中定义返回类型不是 void 的虚方法

sql-server - 是否可以创建 SQL Server Azure VM 但使用自己的许可证?

c# - Azure Functions 需要很长时间才能横向扩展

c# - 从 Azure Function App 读取嵌套配置

python - Azure Function App 上的 EasyAuth 错误自定义 oidc 提供程序