azureazure-functionsazure-blob-triggerazure-configuration

Getting "Azure.Storage.Queues: Value cannot be null" error on Azure function with blob trigger


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').

Error Snapshot

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 blob\n 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"
}

Solution

  • Step 1: Run the following command in cmd (Administrator)

    netstat -ano | findstr :10001

    Result will be like following Cmd result

    Step 2: Pick the first process ID (in this cae it is 38508) and run following command to kill it.

    taskkill /PID 38508 /F

    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)

    Error Snapshot

    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.