I just want to test a simple Azure function with blob trigger but I get following error locally when I try to run/debug the Azure Function.
An unhandled exception has occurred. Host is shutting down.
Functions:
Azure.Storage.Queues: Value cannot be null. (Parameter ‘value’).
Code is also very simple (basically the boiler plate code which comes with the template).
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
namespace Wpm;
public class ThumbnailFunction
{
[FunctionName(nameof(ThumbnailFunction))]
public void Run([BlobTrigger("wpm/{name}", Connection = "wpmStorageConn")]Stream myBlob, string name, ILogger logger)
{
logger.LogInformation($"C# Blob trigger function Processed blobn Name:{name} n Size: {myBlob.Length} Bytes");
}
}
By checking the other similar questions, it looks like there is some problem with connectionstring but I checked that it is same in secrets.json file and same connection string is working fine in Azure Storage explorer and other services.
connectionstring name is wpmStorageConn.
I also tried different things in local.settings.json file, following are its contents:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"wpmStorageConn": "<<HereIsMyConnectionString>>",
"ConnectionStrings:wpmStorageConn": "<<HereIsMyConnectionString>>",
"AzureWebJobsSecretStorageType": "files"
},
"ConnectionStrings": {
"wpmStorageConn": "<<HereIsMyConnectionString>>",
"ConnectionStrings:wpmStorageConn": "<<HereIsMyConnectionString>>"
}
}
and following is secrets.json:
{
"ConnectionStrings:wpmStorageConn": "<<HereIsMyConnectionString>>",
"ConnectionStrings:wpmStorageConn:blob": "https://wpmstorage11.blob.core.windows.net/",
"ConnectionStrings:wpmStorageConn:queue": "https://wpmstorage11.queue.core.windows.net/",
"wpmStorageConn": "UseDevelopmentStorage=true"
}
2
Answers
Step 1: Run the following command in cmd (Administrator)
Result will be like following
Step 2: Pick the first process ID (in this cae it is 38508) and run following command to kill it.
Run the same command again if you find multiple processes, in this case it is only 38508.
Step 3: Type azurite immediately after step 2. (You need to be really quick on this, better to copy paste)
Step 4: Run the project, this error will be gone.
Explanation:
I have tried almost everything which could find in stackoverflow but nothing worked. However, after spending 3 days, I get to know that the error is happening because azurite was not able to start properly. I noticed that error in output window> service dependencies. (Check snapshot below)
To resolve such an error, you need to first check that which process is listening to this (10001) port, then close that process so that azurite can run properly and once azurite properly runs then your project will also run without errors.
However, problem in my case is that, somehow this process automatically starts again after a while. So by the time I ran my project, the process started again and I was facing the same issue again. So Solution is to first kill the process and then immediately run azurite command. After that you can run the project without errors.
There are two approaches to make this function work.
Either you can directly Connect to the dependency like Azure Storage which will store the blob connection string in Secrets.json file for you but in case I didn’t use it and clicked Cancel.
By doing so, you will have given code in .csproj and local.settings.json file respectively.
I am also using default function code.
This configuration gives me expected response.
Used Connect to dependency to connect to Azure Storage account and by doing this, I don’t need to store the connection string in local settings file instead it will automatically store the connection string in Secrets.json file.
Your folder structure should look like below.
You will have the below codes in the mentioned files.
.csproj
local.settings.json
Secrets.json
I got expected response.
One might get this error message target machine actively refused it (127.0.0.1:10000) if Azurite is not running in the machine.