問題描述
Function App出現(xiàn)System.IO.FileNotFoundException異常扩劝,報錯:
Exception while executing function: xxxxxxx踢代,The type initializer for 'xxxxxx.Storage.Adls2.StoreDataLakeGen2Reading' threw an exception. Could not load file or assembly 'Microsoft.Extensions.Configuration, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
問題解答
根據(jù)錯誤的Stock Trace信息看缓淹,異常似乎來源于Azure Function的代碼中引用了Microsoft.Extensions.Configuration依賴乾戏,它的版本是9.0轴总,而在Function所運行的托管主機環(huán)境中沟绪,沒有這個文件怔檩。所以無法加載褪秀。
根據(jù)官網文檔顯示,F(xiàn)unction App的In-Process (進程內模式)薛训,不支持 .NET 9.0媒吗。所以,無法加載 Microsoft.Extension.Configuration v9.0乙埃, 在項目的引用中調整依賴項的版本或者是把Funciton配置切換為Isolated worker(獨立進程模式)闸英。
參考資料
Develop C# class library functions using Azure Functions: https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library?tabs=v4%2Ccmd#supported-versions
當在復雜的環(huán)境中面臨問題锯岖,格物之道需:濁而靜之徐清,安以動之徐生甫何。 云中出吹,恰是如此!