为什么Azure Function v2无法绑定到CloudTable? [英] Why is Azure Function v2 unable to bind to 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
作为输入参数,并且遭受相同的异常.
尽管绑定到
问题是两个Nuget软件包的版本不匹配.创建新解决方案时,我无法复制该问题,并且绑定到 因为我需要在其中输入 现在变得越来越棘手.函数项目引用了 9.3.3和9.3.1的版本差异导致绑定问题.
解决方案是将引用项目中的降级降为9.3.1 或 或者(可能是推荐的):从引用的项目中删除 脑震荡:这真是一团糟:-) 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 and I make it return a subclass of This results in an exception about it being "unable to bind Table to CloudTable". The reason for the exception is a check within the Another function binds to a Although binding to Is this a bug in the client SDKs for Azure Storage or am I doing something wrong? I'm referencing these Nuget packages:
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 because I needed the And now it's getting tricky. The functions project has a reference to and that one has a dependency on 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 Concusion: it's a hot mess :-) 这篇关于为什么Azure Function v2无法绑定到CloudTable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!CloudTable
应该可以工作(CloudTable
的效果很好.与我的解决方案进行比较后发现,我的功能项目引用了另一个依赖于WindowsAzure.Storage (9.3.3)
TableEntity
类型.Microsoft.Azure.WebJobs.Extensions.Storage (3.0.6)
WindowsAzure.Storage (9.3.1)
WindowsAzure.Storage
,并用也包含TableEntity
的Microsoft.Azure.Cosmos.Table
替换. 重要不要将其与已弃用的Microsoft.Azure.CosmosDB.Table
(请注意"DB")混淆.不幸的是,对WindowsAzure.Storage (9.3.3)
的评论告诉我们更改为该错误的软件包./p>
[return: Table("history")]
TableEntity
.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 + "'.");
}
CloudTable
as an input parameter and suffers from the same exception.CloudTable
should work (https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-table#input---c-example---cloudtable) it apparently does not. <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" />
CloudTable
worked just fine. Comparing to my solution revealed that my function project referenced another project which had a dependency onWindowsAzure.Storage (9.3.3)
TableEntity
type in there.Microsoft.Azure.WebJobs.Extensions.Storage (3.0.6)
WindowsAzure.Storage (9.3.1)
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.