如何在Azure函数中使用BlobTrigger绑定到CloudBlockBlob?

时间:2017-10-25 19:20:08

标签: c# azure azure-functions azure-web-app-service azure-webjobssdk

我的项目中有以下功能:

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

当我尝试使用Azure Functions CLI的v1.0.4在本地运行该函数时,出现此错误:

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

我在Azure Functions和WebJobs SDK上看到的所有文档都说支持这一点。

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

2 个答案:

答案 0 :(得分:5)

您可能正在引用一些依赖于WindowsAzure.Storage程序集的不兼容版本(版本8.x.x)的NuGet包。如果是这样,请务必将其删除。除非您使用其他绑定,否则csproj引用应该看起来像这样简单:

<ItemGroup>           
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.6" />
</ItemGroup>

答案 1 :(得分:0)

确保您运行的是Azure存储模拟器:

cd C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator

C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator> AzureStorageEmulator.exe start
Windows Azure Storage Emulator 5.2.0.0 command line tool
Autodetect requested. Autodetecting SQL Instance to use.
Looking for a LocalDB Installation.
Probing SQL Instance: '(localdb)\MSSQLLocalDB'.
Found a LocalDB Installation.
Probing SQL Instance: '(localdb)\MSSQLLocalDB'.
Found SQL Instance (localdb)\MSSQLLocalDB.
Creating database AzureStorageEmulatorDb52 on SQL instance '(localdb)\MSSQLLocalDB'.