我正在尝试在 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
应该管用 (https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-table#input---c-example---cloudtable https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-table#input---c-example---cloudtable)显然没有。
这是 Azure 存储客户端 SDK 中的错误还是我做错了什么?我引用这些 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" />
问题是两个 Nuget 包的版本不匹配。创建新解决方案时,我无法复制问题并绑定到CloudTable
工作得很好。与我的解决方案相比,发现我的函数项目引用了另一个项目,该项目依赖于
WindowsAzure.Storage (9.3.3)
因为我需要TableEntity
在那里输入。
现在事情变得棘手了。功能项目有参考
Microsoft.Azure.WebJobs.Extensions.Storage (3.0.6)
那一个依赖于 https://www.fuget.org/packages/Microsoft.Azure.WebJobs.Extensions.Storage
WindowsAzure.Storage (9.3.1)
9.3.3和9.3.1的版本差异导致了绑定问题。
解决方案是降级参考项目中的 9.3.1
or
或者(可能推荐):删除WindowsAzure.Storage
从引用的项目中并将其替换为Microsoft.Azure.Cosmos.Table
其中还包含TableEntity
. 重要的不要将其与Microsoft.Azure.CosmosDB.Table
(注意“DB”)它已被弃用。不幸的是,评论WindowsAzure.Storage (9.3.3)
告诉我们改成那个不正确的包 https://www.fuget.org/packages/WindowsAzure.Storage.
脑震荡:真是一团糟:-)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)