23

I'm getting the following error when I run the azure function from visual studio.

A ScriptHost error has occurred [1/19/2018 6:40:52 AM] The listener for function 'MyFunctionName' was unable to start. Microsoft.WindowsAzure.Storage: Server encountered an internal error. Please try again after some time.

When I run from the command prompt by running func host start command. I get the following warning. and then it gets stuck on

Host lock lease acquired by instance ID

.

No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

Azure function version: azure-functions-core-tools@2.0.1-beta.22 I'm using Storage Accounts Blob containers and queues.

I'm connecting to Development Storage account, I have checked it that storage emulator is started.

{
  "IsEncrypted": false,
  "Values": {
    "ConnectionStrings:Default": "Server=.\\SQLEXPRESS; Database=TestDb; Trusted_Connection=True;",
    "ConnectionStrings:BlobStorageAccount": "UseDevelopmentStorage=true",

    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
  }
}

FYI.

It was working fine before, But I have got this message in Visual Studio.

your license has gone stale and must be updated. Check for an updated license to continue using this product

So I just deleted the %localappdata% and %temp%, then I tried to run Azure function and after this, I have started getting

The listener for function was unable to start error

So is it related to my visual studio subscription or I mistakenly deleted any required file? Or is this related to something else?

McGuireV10
  • 9,572
  • 5
  • 48
  • 64
Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
  • I think we're going to need some more information to be able to help you. I assume since you're having the problem you're talking about an .NET base Azure Function running on the 1.x runtime? Also, what kind of trigger are you using (storage queue, service bus queue/topic, something else)? If there's any way you can put your project somewhere out in the open (e.g. GitHub) that would be awesome, but if you can't it might just take a little more back and forth. – Drew Marsh Jan 19 '18 at 19:49
  • Thanks Drew, I updated my question – Vivek Nuna Jan 20 '18 at 04:58
  • If you have your function app running in Azure (or somewhere else) using the same host ID, then that instance may take the lease, and your locally running copy would not be running functions.Make sure all of the connection you have fill down. – Joey Cai Jan 23 '18 at 07:42
  • @JoeyCai but it’s not working with VS? – Vivek Nuna Jan 27 '18 at 20:40
  • @JoeyCai any updates on this? – Vivek Nuna Mar 21 '18 at 06:31

14 Answers14

15

if you are running via storage emulator locally then run func settings add AzureWebJobsStorage UseDevelopmentStorage=true in local.settings.json

and if with a normal Azure Storage connection string using func, must set the AzureWebJobsStorage in local.settings.json.
The final JSON would look like this:

{
  // some variables
  "Values": {
    // some variables
    "AzureWebJobsStorage": "UseDevelopmentStorage=true"
  },
}

for more view

Giorgi Gvimradze
  • 1,714
  • 1
  • 17
  • 34
Tahir Alvi
  • 896
  • 2
  • 14
  • 44
11

For anyone that is encountering this issue the following may help...

Azure Durable Functions rely on TableStorage, and the latest version of Azurite (v3) currently doesn't support TableStorage. As such, pull the Azurite repo and switch to the legacy-master (v2) branch and then run npm run start.

RichS
  • 3,097
  • 30
  • 26
  • That was a reason of my problem. Thanks! – Viacheslav Yankov Dec 23 '20 at 21:26
  • 2
    To keep track of v3 support for TableStorage, see this issue: https://github.com/Azure/Azurite/issues/614. You may install the alpha version `npm install -g azurite@alpha` (not tested, though). – Stephan Jan 05 '21 at 09:36
  • 1
    Executing durable functions was working great (uses Azurite) but "regular functions" could not start (Like it was trying to reach the Azure Storage Emulator instead of Azurite) The solution changin `"AzureWebJobsStorage"` in `local.settings.json` to the real local connection string `AccountName=devstoreaccount1;AccountKey=*****;DefaultEndpointsProtocol=http;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;` That forces using Azurite in any case. – BorisD Mar 10 '22 at 15:02
7

I just witnessed this. This link https://github.com/Azure/azure-functions-core-tools/issues/357 indicates Local Storage Emulator may not be running. I stopped debugging. Went to the Cloud Explorer and opened the local nodes to see blob content. This must have started the Local storage emulator. When I hit run again, Azure Functions Tools started up.

jlo-gmail
  • 4,453
  • 3
  • 37
  • 64
6

For me this error was showing up because I didn't have Storage Emulator installed and running. You can install Storage emulator as VS Code plugin from following link. After installing go to VS Code command palette and run Azurite: Start Blob Service. Then run your function locally. It will work fine.

https://marketplace.visualstudio.com/items?itemName=Azurite.azurite

DarthWader
  • 986
  • 1
  • 9
  • 17
  • 1
    Azurite is the way to run Storage Emulator on Mac and Linux. Alternatives to the VS Code plugin are running via a Docker container and installing the Azurite npm package: https://github.com/azure/azurite – Max Ivanov Oct 23 '20 at 01:26
5

I solved the issue doing the following steps: Open up a new terminal and type "azurite". The program will open and keep the window opened. Open visual studio and try to run the function again. Voi la.

delta2_
  • 61
  • 1
  • 3
  • Interesting. Visual Studio was always an integrated development IDE. If "Azurite" is needed, is it an integrated environment yet? – zameb Mar 29 '22 at 16:02
  • Interesting question. After running the function for a few times there is no need to run azurite from outside visual studio. Don´t ask me why, it´s just a weird behaviour from VS. – delta2_ May 11 '22 at 20:01
3

I had the problem too and spend many time. The fix is not from me but I hope the onwer can accept it as solution it has spend me much time in past and it can help others.

The only working fix for me was written in the comment above:

The timer in azure-webjobs-hosts was corrupt. It was fixed after deleting the entry. – Marcel Gelijk Mar 5, 2021 at 9:59

On my cases it ssems to happened if you use a timer trigger and change many on them , make duplicates or switch the time trigger to http trigger and back. If you do som stuff for testing it could harm conflicting entries in azure-webjobs-hosts.

So I delete all entries in locks and timers folder. On starting your timer azure functions all Entries will renewed and it worked

Many thanks to Marcel Gelijk.

[Delete all Entries in that 2 folders1

ingo_ww
  • 171
  • 1
  • 13
3

I am using VS-2022. This issue was resolved using following steps.

  1. Run Azurite, in local machine, using below command

    azurite --silent --location c:\azurite --debug c:\azurite\debug.log

  2. In local.settings.json, use below code:

    "Values": {

    "AzureWebJobsStorage": "UseDevelopmentStorage=true"}

  3. (optional), start the emulator and check that there is no error

That's it!

Prem
  • 303
  • 2
  • 9
1

I was getting this issue when I was using ServiceBusTrigger in my Azure functions.

enter image description here

In my visual studio solution I had two Azure Functions and I was using the same Subscription Name for my two Functions, where one function is to send the data to the Azure Service Bus and the other is for receiving the data.

To Send

private const string _topicName = "factfinder_topic";
private const string _subscriptionName = "subs1";
private static ITopicClient _topicClient;
private static ILogger _logger;
[FunctionName("SendDataToSubscription")]
public static void Run([ServiceBusTrigger(_topicName, _subscriptionName, Connection = "ServiceBusConnectionString")] string mySbMsg, ILogger log) {
    _logger = log;
    PrepareSend().GetAwaiter().GetResult();
    _logger.LogInformation($ "C# ServiceBus topic trigger function processed message: {mySbMsg}");
}

To Receive

private const string _topicName = "factfinder_topic";
private const string _subscriptionName = "subs1";
[FunctionName("FetchDataFromSubscription")]
public static void Run([ServiceBusTrigger(_topicName, _subscriptionName, Connection = "ServiceBusConnectionString")] string mySbMsg, ILogger log) {
    log.LogInformation($ "C# ServiceBus topic trigger function processed message: {mySbMsg}");
}

As you could see that the value of the _subscriptionName is subs1 in both case, and this is wrong, so after changing this to my other subscription name (subs2) in the FetchDataFromSubscription function, the issue was resolved.

Sibeesh Venu
  • 18,755
  • 12
  • 103
  • 140
0

I was also experiencing the same issue. Exiting the Visual Studio and opening it again resolved the issue in my case.

Saurabh Rana
  • 168
  • 3
  • 22
  • one time after VS update it worked for me too. I think it worked, because Azurite was updated. In other cases it possible that it will not work and i had a few other cases that not worked. Only deleting entries in storage azure-webjobs-hosts then works for me. – ingo_ww Aug 01 '22 at 03:33
0

For anyone who bump in this kind of issue, please check this link.

After cleaning the azure storage local container, it solved the issue for me.

FritsJ
  • 71
  • 2
  • 12
0

For anyone else coming across this error when locally running durable functions I found the easiest way to deal with it was by using the VSCode extension "Durable Functions Monitor". I find this an excellent resource for durable functions; using the extension I delete the hub in Azurite storage, which is fast. All the data from any previous executions is removed along with this error.

robs
  • 840
  • 10
  • 15
0

In my case I deleted everything inside %localappdata% and %temp% folders and started again.

tmndungu
  • 167
  • 2
  • 8
0

solved by following this blog.

https://markgossa.com/2018/12/azure-function-listener-for-function.html

"%programfiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" init "%programfiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start

Muni Chittem
  • 988
  • 9
  • 17
-3

I solved this problem by setting UseDevelopmentStorage=false in local.settings.json file.

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

chiru
  • 789
  • 6
  • 5