【Function App】本地通过VS Code调试Function时候遇见无法加载文件错误Microsoft.Extensions.Diagnostics.Abstractions - LuBu0505/My-Code GitHub Wiki

问题描述

本地调试VS Code函数,在执行 func host start的时候报错: image.png

错误信息:

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.25164

Skipping '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

如何来解决这个问题呢?

问题解答

此问题很可能是由更新后系统中的某些版本冲突引起的。需要尝试重新安装 Azure Functions Core Tools,以确保所有组件均已正确安装。

首先,我们可以使用以下命令卸载并重新安装这些工具:

npm uninstall -g azure-functions-core-tools npm install -g azure-functions-core-tools@4 --unsafe-perm true

如果以上方法并不能解决这个问题,如下图: image.png

出现这个问题的原因与最初在本机上安装 Azure Function Runtime插件的方式有关,如果当时是下载安装包(如: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) 并安装修复旧版本Azure Function Core Tools image.png

2)退出VS Code,并重新加载Function项目,启动func host成功! image.png

参考资料

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

当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!