为什么Azure Function v2无法绑定到CloudTable? [英] Why is Azure Function v2 unable to bind to CloudTable?

查看:60
本文介绍了为什么Azure Function v2无法绑定到CloudTable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Visual Studio 2019中运行HTTP触发的v2函数. 应该将其输出写入到称为历史记录"的Azure存储表中.

我已经用

装饰了我的一个功能.

[return: Table("history")]

,我让它返回TableEntity的子类.

这将导致有关无法将表绑定到CloudTable"的异常.出现异常的原因是在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 + "'.");
}

另一个函数绑定到CloudTable作为输入参数,并且遭受相同的异常.

尽管绑定到CloudTable应该可以工作(

问题是两个Nuget软件包的版本不匹配.创建新解决方案时,我无法复制该问题,并且绑定到CloudTable的效果很好.与我的解决方案进行比较后发现,我的功能项目引用了另一个依赖于

的项目

WindowsAzure.Storage (9.3.3)

因为我需要在其中输入TableEntity类型.

现在变得越来越棘手.函数项目引用了

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

并且该对象依赖于

WindowsAzure.Storage (9.3.1)

9.3.3和9.3.1的版本差异导致绑定问题. 解决方案是将引用项目中的降级降为9.3.1

或者(可能是推荐的):从引用的项目中删除WindowsAzure.Storage,并用也包含TableEntityMicrosoft.Azure.Cosmos.Table替换. 重要不要将其与已弃用的Microsoft.Azure.CosmosDB.Table(请注意"DB")混淆.不幸的是,对WindowsAzure.Storage (9.3.3) 的评论告诉我们更改为该错误的软件包./p>

脑震荡:这真是一团糟:-)

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".

I've decorated one my functions with

[return: Table("history")]

and I make it return a subclass of TableEntity.

This results in an exception about it being "unable to bind Table to CloudTable". The reason for the exception is a check within the CloudStorageAccount client's code:

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.

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.

Is this a bug in the client SDKs for Azure Storage or am I doing something wrong? I'm referencing these Nuget packages:

 <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. When creating a new solution I was unable to replicate the issue and binding to CloudTable worked just fine. 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.

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. The solution is to either downgrade to 9.3.1 in the referenced project

or

alternatively (and probably recommended): remove WindowsAzure.Storage from the referenced project and replace it with Microsoft.Azure.Cosmos.Table which also contains TableEntity. Important do NOT confuse this with Microsoft.Azure.CosmosDB.Table (notice the "DB") which is being deprecated. Unfortunately, the comments for WindowsAzure.Storage (9.3.3) tell us to change to exactly that incorrect package.

Concusion: it's a hot mess :-)

这篇关于为什么Azure Function v2无法绑定到CloudTable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆