[英]Azure Function v3 unable to bind blob to CloudBlockBlob
Azure function v3 runtime on VS19 (.Net SDK) with azure-functions-core-tools@3 6.14.4. Azure function v3 运行时在 VS19(.Net SDK)上,带有 azure-functions-core-tools@3 6.14.4。
I'm using a Time trigger and executing read/write on a blob .我正在使用Time 触发器并在 blob 上执行读/写。 But the binding is failing.
但是绑定失败了。 I've followed all instructions on the docs and tried other solutions from StackOverflow for Azure functions v2 but I'm unable to fix the binding.
我已遵循文档上的所有说明,并尝试了 StackOverflow 中针对 Azure 函数 v2 的其他解决方案,但我无法修复绑定。 I've even created the bindings through the portal's integration feature and then used that function.json but the same error is popping up.
我什至通过门户的集成功能创建了绑定,然后使用了 function.json 但弹出相同的错误。
I need to solve 2 problems:我需要解决2个问题:
Fixing the binding error as mentioned below.如下所述修复绑定错误。
[From a different azure function] After publishing of application to Azure, function.json is being overwritten by the server resulting in loss of bindings so retention of bindings in function.json is also required (though it is claimed in the docs that it is managed by serve and editing is not recommended). [From a different azure function] After publishing of application to Azure, function.json is being overwritten by the server resulting in loss of bindings so retention of bindings in function.json is also required (though it is claimed in the docs that it is不推荐由服务和编辑管理)。
Info from the 1st problem:第一个问题的信息:
Here's what the run function looks like:这是运行 function 的样子:
public static async Task Run([TimerTrigger("0 */10 * * * *")]TimerInfo myTimer, ILogger log,
[Blob("container/blob.json", FileAccess.ReadWrite, Connection = "AzureWebJobsStorage")] CloudBlockBlob stateStore)
Function.json: Function.json:
{
"bindings": [
{
"name": "myTimer",
"direction": "in",
"type": "timerTrigger",
"schedule": "0 */10 * * * *"
},
{
"name": "stateStore",
"direction": "inout",
"type": "blob",
"path": "container/blob.json",
"connection": "AzureWebJobsStorage"
}
]
}
host.json主机.json
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
},
"logging": {
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true
}
}
}
}
Csproj: Csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.4.2" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.2.1" />
<PackageReference Include="Azure.Storage.Queues" Version="12.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.14.0" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.4.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.1.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.11" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.1.8" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.4" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="16.153.0" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services" />
</ItemGroup>
</Project>
Error on executing:执行时出错:
1 functions loaded
[14-05-2020 10:17:11] Generating 1 job function(s)
[14-05-2020 10:17:11] Microsoft.Azure.WebJobs.Host: Error indexing method 'FunctionAppName'.
Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'stateStore' to type CloudBlockBlob.
Make sure the parameter Type is supported by the binding.
If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.)
make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
Seems to me it's a problem mixing the multiple storage sdk availables with the latest runtime available.在我看来,将多个存储 sdk 可用与可用的最新运行时混合是一个问题。
WindowsAzure.Storage
is legacy Azure.Storage.Blobs
seems to be wrong too. WindowsAzure.Storage
是旧版Azure.Storage.Blobs
似乎也是错误的。 Try removing them and also add Microsoft.Azure.Storage.Blob
nuget package.尝试删除它们并添加
Microsoft.Azure.Storage.Blob
nuget package。
Azure.Storage.Blobs is the newest nuget package available for dealing with blobs, also Microsoft recommends using it. Azure.Storage.Blobs 是最新的 nuget package 可用于处理 blob,Microsoft 也建议使用它。
I do not know your exact use case but I am using a BlobTrigger that I bind with我不知道您的确切用例,但我使用的是我绑定的 BlobTrigger
public void DoSomething([BlobTrigger("blog-storage/{filename}")] Stream blob, ...)
{
...
}
This is working with the new sdk version.这适用于新的 sdk 版本。
Also here you can find a documentation how to use the sdk.您还可以在此处找到如何使用 sdk 的文档。
Looks like there are problems with the packages again?看来包裹又出问题了? I use Azure Functions v3 based on target framework netcoreapp3.1.
我使用基于目标框架 netcoreapp3.1 的 Azure Functions v3。 For my function with Blob trigger I get the following error message:
对于带有 Blob 触发器的 function,我收到以下错误消息:
The 'DataSync' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'DataSync'. Microsoft.Azure.WebJobs.Host: Can't bind Blob to type 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer'.
The problem occurred after I updated packages Azure.AI.FormRecognizer (3.1.1) and Microsoft.Azure.WebJobs.Extensions.Storage (4.0.5) .在我更新软件包Azure.AI.FormRecognizer (3.1.1)和Microsoft.Azure.WebJobs.Extensions.Storage (4.0.5)后出现问题。
using Azure;
using Azure.AI.FormRecognizer;
using Azure.AI.FormRecognizer.Models;
using Microsoft.Azure.WebJobs;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Table;
<PackageReference Include="Azure.AI.FormRecognizer" Version="3.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.18.0" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
Is anyone aware of any issues with package dependencies?有人知道 package 依赖项有任何问题吗?
I found a solutions for me: " Azure.AI.FormRecognizer " depends on .NETStandard, version = v2.0 " Microsoft.Azure.WebJobs.Extensions.Storage " depends on .NETStandard, version = v2.0我为我找到了一个解决方案:“ Azure.AI.FormRecognizer ”取决于.NETStandard,版本 = v2.0 “ Microsoft.Azure.WebJobs.Extensions.Storage ”取决于.NETStandard,版本 = v2。
Before I had the following target framework for my function: .NET Core 3.1在我的 function 有以下目标框架之前:.NET Core 3.1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.