看来我不能拥有使用Blob绑定的活动功能。下面给出了运行时错误:
[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)
{
...
}
我收到多个失败的绑定错误消息。耐用功能不能解析绑定吗?
编辑:添加错误消息(降低冗长程度...):
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()
答案 0 :(得分:0)
确保已安装所需的软件包,例如
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.3" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" />
在blob输入绑定中,对于绑定类型CloudBlobDirectory
,路径应采用containerName/directoryName
的格式。请参阅样本中的container
,这是可疑的。
我们还可以将传入参数blobName放在blob路径中,以直接获取CloudBlockBlob。
[Blob("containerName/directoryName/{blobName}", FileAccess.ReadWrite, Connection = "AzureWebJobsStorage")] CloudBlockBlob blob
更新
确保我们没有安装WindowsAzure.Storage
> = v9.3.2,绑定到与存储相关的数据类型(如CloudBlockBlob
)时似乎存在错误。请参阅跟踪的issue。
创建v2功能项目时,默认情况下Microsoft.NET.SDK.Functions
引用WindowsAzure.Storage
9.3.1。此版本运行良好,无需单独安装软件包。
或者我们可以在新版本的Storage SDK中使用Stream
或string
之类的数据类型。