Error: Could not load file or assembly 'Microsoft.Azure.WebJobs.Script.Abstractions

Error: Could not load file or assembly 'Microsoft.Azure.WebJobs.Script.Abstractions

我正尝试按照 Microsoft 指南在本地 运行 一个 Azure 函数: https://docs.microsoft.com/nl-nl/azure/azure-functions/create-first-function-cli-python?tabs=azure-cli%2Cbash%2Cbrowser#create-venv

无论我尝试什么,当我尝试使用“func start”启动该功能时,我都会一遍又一遍地遇到相同的错误:

 Found Python version 3.8.0 (py).

 Azure Functions Core Tools
 Core Tools Version:       4.0.4544 Commit hash: N/A  (64-bit)
 Function Runtime Version: 4.3.2.18186

 Could not load file or assembly 'Microsoft.Azure.WebJobs.Script.Abstractions, 
 Version=1.0.0.0, Culture=neutral, PublicKeyToken=3c5b9424214e8f8c'. The system cannot find 
 the file specified. 

我的文件设置如下

Host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  }
}

local.setting.json

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true"
  }
}

requirements.txt

azure-functions

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "Anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}

init.py

import logging

import azure.functions as func


def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )

如有任何帮助,我们将不胜感激!

我也遇到过这个。不确定是什么原因造成的。

但对我来说修复它的是下载、卸载并重新安装 Azure Functions Core Tools (使用 'repair' 只是返回一个通用的“因错误而失败”,我不得不杀死 PowerToys)


不确定是否有必要,但我也清除了我的 nuget 缓存

dotnet nuget locals all -c
dotnet restore # in your sln folder

并重新安装了我的 vscode Azure 插件

我 运行 遇到完全相同的问题,而 运行 使用 Azure CLI 的 Azure Function v4:

  "azure-cli": "2.37.0",
  "azure-cli-core": "2.37.0",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {}

我通过重新安装 Azure Functions Core Tools(Lightfire 的部分答案)修复了它。所有其他操作对我没有影响。

Link 到 Install Azure Functions Core Tools