Kaja
Kaja

Reputation: 3057

Activity function should return an IEnumerable<IListBlobItem>

I have an activity function which should return an IEnumerable<IListBlobItem> as follows:

[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;
}

In my Orchestrator I am calling this activity function as follows:

 IEnumerable<IListBlobItem> blobs = await context.CallActivityAsync<IEnumerable<IListBlobItem>>("process_file_GetBlobList", null);

by debugging I get no error message, but in run time I get this message:

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'

Do have any idea, how can I call my activity function via CallActivityAsync?

Upvotes: 1

Views: 820

Answers (3)

gashach
gashach

Reputation: 420

I believe the line IEnumerable<IListBlobItem> blobs = new IListBlobItem[0]; needs to be rewritten. try IEnumerable<IListBlobItem> blobs = new List<IListBlobItem>();

Upvotes: 0

subham
subham

Reputation: 174

Thats because you are having list of Interface which definetly can't be initialized. You can create a new class implementing IListofBobItems and then return List of newly created class from GetbobList method

Upvotes: 0

Sajeetharan
Sajeetharan

Reputation: 222582

Change it to List and see,

  List<ListBlobItem> blobs = await context.CallActivityAsync<List<ListBlobItem>>("process_file_GetBlobList", null);

however, you can fix the above error by changing the blobs to type var.

Upvotes: 1

Related Questions