Can Durable Activity Functions use binding attributes?

我只是一个虾纸丫 提交于 2019-12-11 21:30:08

问题


It appears that I cannot have an activity function which uses a Blob binding. The following gives runtime errors:

[StorageAccount("AzureWebJobsStorage")]
[FunctionName("LoadBlobFromBlobStorage")]
public static async Task<string> Run([ActivityTrigger] string blobName,
[Blob("containerName/directoryName/{blobName}", FileAccess.ReadWrite, Connection = AzureWebJobsStorage")] CloudBlockBlob blob,
ILogger log)
{
    ...
}

I get multiple failed binding error messages. Do Durable Functions not resolve bindings?

EDIT: add error messages (with reduced verbosity ...):

Azure Functions Core Tools (2.4.379 Commit hash: ab2c4db3b43f9662b82494800dd770698788bf2d)
Function Runtime Version: 2.0.12285.0
2019-02-21T18:25:32.165 [Error] Error indexing method 'LoadBlobFromBlobStorage'
Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException : Error indexing method 'LoadBlobFromBlobStorage' ---> System.InvalidOperationException : Can't bind Blob to type 'Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob'.
Possible causes:
1) Tried binding to 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory...' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory... .
2) Tried binding to 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer...' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory... .
3) Tried binding to 'Microsoft.Azure.WebJobs.Host.Blobs.Bindings.BlobsExtensionConfigProvider+MultiBlobContext, Microsoft.Azure.WebJobs.Extensions.Storage, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory... .
4) Tried binding to 'System.IO.Stream, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory... .
5) Tried binding to 'Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob...' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory... .
6) Tried binding to 'Microsoft.WindowsAzure.Storage.Blob.CloudPageBlob...' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory... .
7) Tried binding to 'Microsoft.WindowsAzure.Storage.Blob.CloudAppendBlob...' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory... .
8) Tried binding to 'Microsoft.WindowsAzure.Storage.Blob.ICloudBlob...' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory... .

   at async Microsoft.Azure.WebJobs.Host.Bindings.GenericCompositeBindingProvider`1.TryCreateAsync[TAttribute](BindingProviderContext context) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\BindingProviders\GenericCompositeBindingProvider.cs : 89
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

回答1:


Make sure the package required are installed e.g.

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.3" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" />

And in the blob input binding, for binding type CloudBlobDirectory, the path should be in the format of containerName/directoryName. See container in your sample which is suspicious.

We could also put the incoming parameter blobName in blob path to get CloudBlockBlob directly.

[Blob("containerName/directoryName/{blobName}", FileAccess.ReadWrite, Connection = "AzureWebJobsStorage")] CloudBlockBlob blob 

Update

Make sure we don't install WindowsAzure.Storage >= v9.3.2, there seems a bug when binding to Storage related data type like CloudBlockBlob. See the issue tracked.

When we create a v2 Function Project, Microsoft.NET.SDK.Functions references WindowsAzure.Storage 9.3.1 by default. This version works well, no need to install the package separately.

Or we could use datatype like Stream or string with new version Storage SDK.



来源:https://stackoverflow.com/questions/54813887/can-durable-activity-functions-use-binding-attributes

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