簡體   English   中英

Azure Function v3 無法將 blob 綁定到 CloudBlockBlob

[英]Azure Function v3 unable to bind blob to CloudBlockBlob

Azure function v3 運行時在 VS19(.Net SDK)上,帶有 azure-functions-core-tools@3 6.14.4。

我正在使用Time 觸發器在 blob 上執行讀/寫 但是綁定失敗了。 我已遵循文檔上的所有說明,並嘗試了 StackOverflow 中針對 Azure 函數 v2 的其他解決方案,但我無法修復綁定。 我什至通過門戶的集成功能創建了綁定,然后使用了 function.json 但彈出相同的錯誤。

我需要解決2個問題:

  1. 如下所述修復綁定錯誤。

  2. [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不推薦由服務和編輯管理)。

第一個問題的信息:

這是運行 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:

{
  "bindings": [
    {
      "name": "myTimer",
      "direction": "in",
      "type": "timerTrigger",
      "schedule": "0 */10 * * * *"
    },
    {
      "name": "stateStore",
      "direction": "inout",
      "type": "blob",
      "path": "container/blob.json",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

主機.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.).

在我看來,將多個存儲 sdk 可用與可用的最新運行時混合是一個問題。

WindowsAzure.Storage是舊版Azure.Storage.Blobs似乎也是錯誤的。 嘗試刪除它們並添加Microsoft.Azure.Storage.Blob nuget package。

Azure.Storage.Blobs 是最新的 nuget package 可用於處理 blob,Microsoft 也建議使用它。

我不知道您的確切用例,但我使用的是我綁定的 BlobTrigger

public void DoSomething([BlobTrigger("blog-storage/{filename}")] Stream blob, ...)
{
...
}

這適用於新的 sdk 版本。

您還可以在此處找到如何使用 sdk 的文檔。

看來包裹又出問題了? 我使用基於目標框架 netcoreapp3.1 的 Azure Functions v3。 對於帶有 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'.

在我更新軟件包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">

有人知道 package 依賴項有任何問題嗎?

我為我找到了一個解決方案:“ Azure.AI.FormRecognizer ”取決於.NETStandard,版本 = v2.0Microsoft.Azure.WebJobs.Extensions.Storage ”取決於.NETStandard,版本 = v2。

在我的 function 有以下目標框架之前:.NET Core 3.1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM