亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么 Azure Function v2 無法綁定到 CloudTable?

為什么 Azure Function v2 無法綁定到 CloudTable?

C#
慕斯709654 2023-07-22 18:16:46
我正在嘗試在 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 + "'.");}另一個函數綁定到 aCloudTable作為輸入參數并遇到相同的異常。盡管綁定到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" />
查看完整描述

2 回答

?
胡子哥哥

TA貢獻1825條經驗 獲得超6個贊

問題是兩個 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從引用的項目中刪除并將其替換為Microsoft.Azure.Cosmos.Table也包含TableEntity.?重要的是不要將其與Microsoft.Azure.CosmosDB.Table正在棄用的(注意“DB”)混淆。


查看完整回答
反對 回復 2023-07-22
?
瀟瀟雨雨

TA貢獻1833條經驗 獲得超4個贊

我遇到了類似的問題,當我嘗試啟動 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 (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

如前所述,我在我的項目中看到有WindowsAzure.Storage一個警告標志并聲明它已被棄用。

http://img2.sycdn.imooc.com/64bbacb3000100d407110849.jpg

讓我的項目監聽表存儲事件的修復方法是更改使用。顯然我已經在我的項目中使用了對 Cosmos 的引用Microsoft.Azure.WebJobs.Extensions.Storage

http://img4.sycdn.imooc.com/64bbacc00001900407070519.jpg

通過刪除 using: 來解決這個問題,using Microsoft.WindowsAzure.Storage.Table;只需將其替換為using Microsoft.Azure.Cosmos.Table;

但請注意,如果您正在使用ObjectFlattenerRecomposer.Core,它仍在使用Microsoft.WindowsAzure.Storage.Table并且尚無法使用Microsoft.Azure.Cosmos.Table。我已就此事聯系開發商。



查看完整回答
反對 回復 2023-07-22
  • 2 回答
  • 0 關注
  • 190 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號