Thursday, 27 December 2018

Azure Function - The listener for function was unable to start

Issue

When debugging one of my Azure Functions in Visual Studio 2017, I got the error below:

“The listener for function 'MyFunction' was unable to start. Microsoft.WindowsAzure.Storage: No connection could be made because the target machine actively refused it. System.Net.Http: No connection could be made because the target machine actively refused it. System.Private.CoreLib: No connection could be made because the target machine actively refused it.”

image

After a Google search, I didn’t find much on the error message. I figured I’d write up the solution for the next person who has this problem.

Solution

I figured that this may be a firewall issue or a problem with one of the services that wasn’t started so I tried to eliminate those causes. I found that all services were started and that even with the firewall disabled, I still had the issue. I resorted to the classic turn it off and on again and that still didn’t fix it.

Eventually, it occurred to me to check that the Azure Storage Emulator was started and I found that it wasn’t. To check if it’s started, run the command below:

image

If you see IsRunning as False like above then you’re going to need to initialize and start the Azure Storage Emulator by running the commands below:

We can then check that the Azure Storage Emulator is running again by checking the status and we can see IsRunning is now True:

image

You should now be good to go and can now debug your functions.

Thursday, 20 December 2018

Publish Azure Function with Visual Studio 2017

Introduction

In my last post, I demonstrated how to create a new .NET Core Azure Function. In this post, I’ll demo how to publish your Azure Function using Visual Studio.

This post assumes that you’ve created your Azure Function already. If you need to go back over how to do that, click here.

Publish Azure Function with Visual Studio 2017

1) Right click your project and click Publish

image_thumb[25]

2) If you have an existing Azure Function App already deployed in Azure then you can choose Select Existing to use an existing one however I’m creating one from scratch so I’ll choose Create New

image_thumb[26]

3) Log into Azure and fill out all the details then click Create

image_thumb[27]

You’ll be prompted to upgrade the version of Azure Function as we need V2, not V1 for .NET Core. If so, click Yes.

image_thumb[28]

4) After a few seconds, Visual Studio completes the deployment and you can now see your new Azure Function in the Azure Portal

image_thumb[29]

5) On the overview tab, copy the URL into PostMan

image_thumb[30]

5) Click on Manage and copy down your function key. You can create a new key if you want.

image_thumb[31]

6) In PostMan, add the key and the path to the HttpTrigger function as below

https://httptrigger-markgossa.azurewebsites.net/api/HttpTrigger?code=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

You can now click Send and see your output

image_thumb[33]

There you have it! .NET Core Azure Function published to Azure in very little time. You can find the project code on GitHub here.