问题描述
参考官方文档,通过CS Code创建JavaScription Function,在本地远行时候出现:
Value cannot be null. (Parameter 'provider')
问题分析
第一步:开启Function的详细日志,在VS Code中进入Funciton所在目录,然后再 Terminal 中启动本地调试
输入: func start --verbose
第二步:分析日志
详细日志中,发现错误发生在 Downloading extension bundle 这一步:
[2022-01-06T07:47:24.404Z] Loading functions metadata
[2022-01-06T07:47:24.509Z] Reading functions metadata
[2022-01-06T07:47:24.518Z] 0 functions found
[2022-01-06T07:47:24.535Z] 0 functions loaded
[2022-01-06T07:47:24.540Z] Looking for extension bundle Microsoft.Azure.Functions.ExtensionBundle at C:\Users\Administrator\.azure-functions-core-tools\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle
[2022-01-06T07:47:24.544Z] Fetching information on versions of extension bundle Microsoft.Azure.Functions.ExtensionBundle available on https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/index.json
[2022-01-06T07:47:25.432Z] Looking for extension bundle Microsoft.Azure.Functions.ExtensionBundle at C:\Users\Administrator\.azure-functions-core-tools\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle
[2022-01-06T07:47:25.435Z] Fetching information on versions of extension bundle Microsoft.Azure.Functions.ExtensionBundle available on https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/index.json
[2022-01-06T07:47:27.250Z] Downloading extension bundle from https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/3.3.0/Microsoft.Azure.Functions.ExtensionBundle.3.3.0_any-any.zip to C:\Users\Administrator\AppData\Local\Temp\fc4f430a-f517-4cd9-9192-c6ce9368f679\Microsoft.Azure.Functions.ExtensionBundle.3.3.0.zip
Value cannot be null. (Parameter 'provider')
[2021-12-22T01:34:45.182Z] Stopping host...
[2021-12-22T01:34:45.187Z] Host shutdown completed.
问题解答
经过问题分析,问题根源是下载extension bundle失败了。 所以可能需要多次手动尝试下载 Extension Bundle文件。
下载链接: https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/3.3.0/Microsoft.Azure.Functions.ExtensionBundle.3.3.0_any-any.zip
下载完成后,把文件解压放入Azure Function Core Tools 目录下,再运行function就可以可以解决 Value cannot be null. (Parameter 'provider') 问题
Extension Bundle文件目录
C:\Users\Administrator\.azure-functions-core-tools\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle\3.3.0
最终目录是以下内容:
<img src="https://img2020.cnblogs.com/blog/2127802/202201/2127802-20220106200717309-1479322098.png" width="600" align="middle" loading="lazy" style="border: 2px solid darkblue;" />
参考资料
在 Azure 中使用 Visual Studio Code 创建 JavaScript 函数:https://docs.microsoft.com/zh-cn/azure/azure-functions/create-first-function-vs-code-node