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
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
And reinstalled my vscode Azure plugins
I ran into exactly the same problem while running the Azure Function v4 using the Azure CLI:
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