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

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 21:01:04

问题


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


回答1:


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>



回答2:


Make sure you are running the Azure Storage Emulator:

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'.


来源:https://stackoverflow.com/questions/46940492/how-can-i-use-a-blobtrigger-to-bind-to-cloudblockblob-in-an-azure-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!