简体   繁体   English

为什么 Azure Function v2 无法绑定到 CloudTable?

[英]Why is Azure Function v2 unable to bind to CloudTable?

I'm trying to run an HTTP triggered v2 function in Visual Studio 2019. It's supposed to write its output into an Azure Storage Table called "history".我正在尝试在 Visual Studio 2019 中运行 HTTP 触发的 v2 函数。它应该将其输出写入名为“history”的 Azure 存储表中。

I've decorated one my functions with我装饰了一个我的功能

[return: Table("history")]

and I make it return a subclass of TableEntity .我让它返回一个TableEntity的子类。

This results in an exception about it being "unable to bind Table to CloudTable".这会导致“无法将 Table 绑定到 CloudTable”的异常。 The reason for the exception is a check within the CloudStorageAccount client's code:异常的原因是CloudStorageAccount客户端代码中的检查:

bool bindsToEntireTable = tableAttribute.RowKey == null;
if (bindsToEntireTable)
{
  // This should have been caught by the other rule-based binders. 
  // We never expect this to get thrown. 
  throw new InvalidOperationException("Can't bind Table to type '" + parameter.ParameterType + "'.");
}

Another function binds to a CloudTable as an input parameter and suffers from the same exception.另一个函数绑定到CloudTable作为输入参数,并遇到相同的异常。

Although binding to CloudTable should work ( https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-table#input---c-example---cloudtable ) it apparently does not.虽然绑定到CloudTable应该可以工作( https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-table#input---c-example---cloudtable )它显然可以不是。

Is this a bug in the client SDKs for Azure Storage or am I doing something wrong?这是 Azure 存储客户端 SDK 中的错误还是我做错了什么? I'm referencing these Nuget packages:我正在引用这些 Nuget 包:

 <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.8.3" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.6" />
    <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.2.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />

The problem is a version mismatch of two Nuget packages.问题是两个 Nuget 包的版本不匹配。 When creating a new solution I was unable to replicate the issue and binding to CloudTable worked just fine.在创建新解决方案时,我无法复制问题并且绑定到CloudTable工作得很好。 Comparing to my solution revealed that my function project referenced another project which had a dependency on与我的解决方案相比,我的函数项目引用了另一个依赖于

WindowsAzure.Storage (9.3.3)

because I needed the TableEntity type in there.因为我在那里需要TableEntity类型。

And now it's getting tricky.现在它变得棘手了。 The functions project has a reference to功能项目有参考

Microsoft.Azure.WebJobs.Extensions.Storage (3.0.6)

and that one has a dependency on 并且那个依赖于

WindowsAzure.Storage (9.3.1)

The version difference of 9.3.3 and 9.3.1 leads to the binding problems. 9.3.3 和 9.3.1 的版本差异导致绑定问题。 The solution is to either downgrade to 9.3.1 in the referenced project解决方案是在引用的项目中降级到 9.3.1

or或者

alternatively (and probably recommended): remove WindowsAzure.Storage from the referenced project and replace it with Microsoft.Azure.Cosmos.Table which also contains TableEntity .或者(可能推荐):从引用的项目中删除WindowsAzure.Storage并将其替换为Microsoft.Azure.Cosmos.Table ,其中也包含TableEntity Important do NOT confuse this with Microsoft.Azure.CosmosDB.Table (notice the "DB") which is being deprecated.重要的是不要将此与Microsoft.Azure.CosmosDB.Table (注意“DB”)混淆,后者已被弃用。 Unfortunately, the comments for WindowsAzure.Storage (9.3.3) tell us to change to exactly that incorrect package .不幸的是, WindowsAzure.Storage (9.3.3)的注释告诉我们更改为完全不正确的 package

Concusion: it's a hot mess :-)脑震荡:这是一团糟:-)

I had similar problems, I got this when I tried to start my Azure Function V3:我遇到了类似的问题,当我尝试启动 Azure Function V3 时遇到了这个问题:

Error indexing method 'Function' Cannot bind parameter 'Table' to type CloudTable. Make sure the parameter Type is supported by the binding. If you're using binding extensions (eg Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (eg builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

As stated, I saw in my project that the WindowsAzure.Storage had a warning sign and stated that it is deprecated.如上所述,我在我的项目中看到WindowsAzure.Storage有一个警告标志并声明它已被弃用。

在此处输入图片说明

The fix for me to get my project listening on Table Storage events was to change the using.让我的项目侦听表存储事件的修复方法是更改​​ using。 Apparently I already got a reference to Cosmos in my project using the Microsoft.Azure.WebJobs.Extensions.Storage显然,我已经使用Microsoft.Azure.WebJobs.Extensions.Storage在我的项目中获得了对 Cosmos 的引用

在此处输入图片说明

Fixing the issue for me by removing the using: using Microsoft.WindowsAzure.Storage.Table;通过删除 using 为我解决问题: using Microsoft.WindowsAzure.Storage.Table; and just replace it with using Microsoft.Azure.Cosmos.Table;using Microsoft.Azure.Cosmos.Table;替换它using Microsoft.Azure.Cosmos.Table;

But be aware if you are using the ObjectFlattenerRecomposer.Core it is still using Microsoft.WindowsAzure.Storage.Table and will not work with Microsoft.Azure.Cosmos.Table yet.但请注意,如果您使用的是ObjectFlattenerRecomposer.Core,它仍在使用Microsoft.WindowsAzure.Storage.Table并且还不能与Microsoft.Azure.Cosmos.Table一起使用。 I have contacted the developer regarding this.我已经就此事联系了开发商。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在Azure Function v2中运行的ClaimsPrincipal中缺少“ identityProvider”声明? - Why is the 'identityProvider' claim missing in the ClaimsPrincipal running in an Azure Function v2? Microsoft.Azure.WebJobs.Host:无法绑定参数“ myContext”以键入DataContext。 Azure Function v2中的错误 - Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'myContext' to type DataContext. error in Azure Function v2 在天蓝色功能V2中用ILogger替换TraceWriter - Replace TraceWriter With ILogger in azure function V2 分段数据上传 - Azure Function V2 - Multipart Data Upload - Azure Function V2 具有Azure Function V2的SendGrid邮件程序 - SendGrid mailer with Azure Function V2 在 azure 函数 v2 中设置查询参数 - setting query parameter in azure function v2 Azure Function V2 中的 JWT 验证 - JWT Validation in Azure Function V2 部署的Azure功能(v2)未运行 - Deployed Azure Function (v2) not running Azure Function v2 和连接字符串 - Azure Function v2 and connection strings 为什么在我的 Azure Function v2 中注入的 ILogger 缺少 APPINSIGHTS_INSTRUMENTATIONKEY? - Why is the ILogger injected in my Azure Function v2 missing the APPINSIGHTS_INSTRUMENTATIONKEY?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM