Azure Functions - No such host is known

I’ve been building a queue reader with Azure Functions recently and ran into an exception that took me a while to fix. Hopefully this will help others short-circuit the process :sunglasses:

Here is the flow:

  1. I’m using Visual Studio Code.
  2. I have a simple queue triggered function that is bound to an Azure Queue Storage.
  3. In a PowerShell terminal I start my function.
  4. The function starts as expected but after a few seconds an exception is thrown.

Visual Studio Code showing an exception message

The exception reads:

An unhandled exception has occurred. Host is shutting down.
Microsoft.WindowsAzure.Storage: No such host is known. System.Net.Http: No such host is known. System.Private.CoreLib: No such host is known.

The problem was with my AZURE_STORAGE_CONNECTION_STRING variable. This is where my queue trigger function gets the connection string which it uses to bind to the queue storage.

I set the variable in my settings.local.json file but as you can see in the screenshot above, the Azure Functions runtime notices that I have an Environment Variable with the same name and uses that instead.

PowerShell terminal showing that the environment variable value is being used

Checking the environment variable in the terminal I can see that it’s pointing to a storage account that doesn’t exist! :beetle:

PowerShell terminal showing the incorrect environment variable value

Updating the environment variable with the correct connection string resolves the exception. :+1: