Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a BlobTrigger to bind to CloudBlockBlob in an Azure Function?

I have the following function in my project:

[FunctionName("my-func")]
public static async Task Run([BlobTrigger("data/{name}")] CloudBlockBlob blob, string name, TraceWriter log)
{
    log.Info($"Started Processing: {name}");

    await blob.DeleteAsync();

    log.Info($"Finished Processing: {name}");
}

When I attempt to run the function locally using v1.0.4 of the Azure Functions CLI I get this error:

Microsoft.Azure.WebJobs.Host: Error indexing method 'SampleFunction.Run'. Microsoft.Azure.WebJobs.Host: Can't bind BlobTrigger to type 'Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob'.

All documentation I have seen for Azure Functions and WebJobs SDK say this is supported.

https://github.com/Azure/azure-webjobs-sdk/wiki/Blobs#-types-that-you-can-bind-to-blobs

like image 596
Mike Avatar asked Oct 25 '17 19:10

Mike


Video Answer


1 Answers

You are probably referencing some NuGet package that has a dependency on non-compatible version of WindowsAzure.Storage assembly (version 8.x.x). If so, be sure to remove it. Unless you are using some additional binding, your csproj references should look as simple as this:

<ItemGroup>           
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.6" />
</ItemGroup>
like image 177
Mikhail Shilkov Avatar answered Sep 23 '22 19:09

Mikhail Shilkov