【Function App】本地通過VS Code調(diào)試Function時候遇見無法加載文件錯誤Microsoft.Extensions.Diagnostics.Abstractions
問題描述
本地調(diào)試VS Code函數(shù),在執(zhí)行 func host start的時候報(bào)錯:

錯誤信息:
> func host start
Azure Functions Core Tools
Core Tools Version: 4.0.7317 Commit hash: N/A +5ca56d37938824531b691f094d0a77fd6f51af20 (64-bit)
Function Runtime Version: 4.1038.300.25164Skipping 'JAVA_HOME' from local settings as it's already defined in current environment variables.
[2025-06-05T11:28:18.312Z] Error starting Rpc Initialization Service. Handling error and continuing.
[2025-06-05T11:28:18.327Z] Microsoft.Azure.WebJobs.Script: Failed to start Rpc Server. Check if your app is hitting connection limits. System.Private.CoreLib: Could not load file or assembly 'Microsoft.Extensions.Diagnostics.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
[2025-06-05T11:28:19.988Z] A host error has occurred during startup operation '3e42ddc0-cd83-41c8-921d-70315100228a'.
[2025-06-05T11:28:19.990Z] System.Private.CoreLib: Could not load file or assembly 'Microsoft.Extensions.Diagnostics.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
[2025-06-05T11:28:20.001Z] Failed to stop host instance 'f6264ddc-95ad-4e41-86d8-44859261268c'.
[2025-06-05T11:28:20.002Z] Microsoft.Azure.WebJobs.Host: The host has not yet started.
Value cannot be null. (Parameter 'provider')
[2025-06-05T11:28:20.753Z] Host startup operation has been canceled
如何來解決這個問題呢?
問題解答
此問題很可能是由更新后系統(tǒng)中的某些版本沖突引起的。需要嘗試重新安裝 Azure Functions Core Tools,以確保所有組件均已正確安裝。
首先,我們可以使用以下命令卸載并重新安裝這些工具:
npm uninstall -g azure-functions-core-tools
npm install -g azure-functions-core-tools@4 --unsafe-perm true
如果以上方法并不能解決這個問題,如下圖:

出現(xiàn)這個問題的原因與最初在本機(jī)上安裝 Azure Function Runtime插件的方式有關(guān),如果當(dāng)時是下載安裝包(如:func-cli-x64.msi)來安裝的,則使用npm方式就不可以。
可以使用如下步驟解決問題:
1) 重新下載Function Core Tools:(https://docs.azure.cn/zh-cn/azure-functions/functions-run-local?tabs=windows%2Cisolated-process%2Cnode-v4%2Cpython-v2%2Chttp-trigger%2Ccontainer-apps&pivots=programming-language-csharp#install-the-azure-functions-core-tools) 并安裝修復(fù)舊版本Azure Function Core Tools

2)退出VS Code,并重新加載Function項(xiàng)目,啟動func host成功!

參考資料
Error after updating Azure Functions Core Tools to version 4.0.6594:https://learn.microsoft.com/en-us/answers/questions/2118820/error-after-updating-azure-functions-core-tools-to
當(dāng)在復(fù)雜的環(huán)境中面臨問題,格物之道需:濁而靜之徐清,安以動之徐生。 云中,恰是如此!

浙公網(wǎng)安備 33010602011771號