skip to Main Content

I’m trying to run an Azure Function locally following the Microsoft guide:
https://learn.microsoft.com/nl-nl/azure/azure-functions/create-first-function-cli-python?tabs=azure-cli%2Cbash%2Cbrowser#create-venv

Whatever I try I get the same error over and over again when i try to start the function using "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. 

My files are set up as follows

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
        )

Any help would be appreciated!

2

Answers


  1. I came across this too. Not sure what caused it.

    But what fixed it for me was to download, uninstall, and reinstall the Azure Functions Core Tools
    (using ‘repair’ just returned a generic "Failed due to error", and I had to kill PowerToys)


    Not sure if it’s necessary, but I also cleared my nuget cache

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

    And reinstalled my vscode Azure plugins

    Login or Signup to reply.
  2. I ran into exactly the same problem while running the Azure Function v4 using the Azure CLI:

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

    I fixed it by just reinstalling Azure Functions Core Tools (part of the answer by Lightfire) All the other actions had no effect for me.

    Link to Install Azure Functions Core Tools

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search