Azure Function v3 无法将 blob 绑定到 CloudBlockBlob。

问题描述 投票:0回答:1

Azure函数V3运行在VS19 (.Net SDK)上,使用的是azure-functions-core-tools@3 6.14.4。

我使用的是 时间触发 和执行 读写.但是绑定失败了.我遵循了文档上的所有说明,并尝试了StackOverflow for Azure functions v2的其他解决方案,但我无法修复绑定.我甚至通过门户的集成功能创建了绑定,然后使用该function.json,但同样的错误正在弹出。

我需要解决2个问题。

  1. 修正下面提到的绑定错误

  2. 来自不同的azure函数】在将应用发布到Azure后,function.json被服务器覆盖导致绑定丢失,所以还需要保留function.json中的绑定(虽然文档中声称是由service管理,不建议编辑)。

第1个问题的信息。

下面是运行函数的样子。

public static async Task Run([TimerTrigger("0 */10 * * * *")]TimerInfo myTimer, ILogger log, 
[Blob("container/blob.json", FileAccess.ReadWrite, Connection = "AzureWebJobsStorage")] CloudBlockBlob stateStore)

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

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[1.*, 2.0.0)"
  },
  "logging": {
    "applicationInsights": {
      "samplingExcludedTypes": "Request",
      "samplingSettings": {
        "isEnabled": true
      }
    }
  }
}

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>

执行时出错。

 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.).
azure azure-functions azure-storage-blobs azure-function-app azure-functions-core-tools
1个回答
1
投票

在我看来,这是一个问题,混合多个存储SDK可用的最新运行时。

WindowsAzure.Storage 是传统的 Azure.Storage.Blobs 似乎也不对。试着把它们去掉,同时添加 Microsoft.Azure.Storage.Blob nuget包。

© www.soinside.com 2019 - 2024. All rights reserved.