我正在尝试在 Visual Studio 2019 中运行 HTTP 触发的 v2 函数.它应该将其输出写入到名为历史"的 Azure 存储表中.
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")]
我让它返回 TableEntity
的子类.
and I make it return a subclass of TableEntity
.
这会导致无法将表绑定到 CloudTable"的异常.异常的原因是 CloudStorageAccount
客户端代码中的检查:
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 + "'.");
}
另一个函数作为输入参数绑定到 CloudTable
并遇到相同的异常.
Another function binds to a CloudTable
as an input parameter and suffers from the same exception.
虽然绑定到 CloudTable
应该可以工作(https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-table#input---c-example---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.
这是 Azure 存储的客户端 SDK 中的错误还是我做错了什么?我引用了这些 Nuget 包:
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" />
问题是两个 Nuget 包的版本不匹配.在创建新解决方案时,我无法复制问题并且绑定到 CloudTable
工作得很好.与我的解决方案相比,我发现我的函数项目引用了另一个依赖于
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)
因为我需要 TableEntity
类型.
现在变得棘手了.函数项目引用了
And now it's getting tricky. The functions project has a reference to
Microsoft.Azure.WebJobs.Extensions.Storage (3.0.6)
并且依赖于
WindowsAzure.Storage (9.3.1)
9.3.3 和 9.3.1 的版本差异导致绑定问题.解决方案是在引用的项目中降级到 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
或
或者(并且可能推荐):从引用的项目中删除 WindowsAzure.Storage
并将其替换为还包含 TableEntity 的
Microsoft.Azure.Cosmos.Table
代码>.重要不要将此与已弃用的 Microsoft.Azure.CosmosDB.Table
(注意DB")混淆.不幸的是,WindowsAzure.Storage (9.3.3)
的评论告诉我们更改为完全不正确的包.
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!