Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing value for AzureWebJobsStorage in local.settings.json local development in Visual Studio 2017

I'm developing a azure function locally, with the Storage Emulator and de Storage Explorer opened.

File tree

File tree

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsDashboard": "UseDevelopmentStorage=true"
  },
  "ConnectionStrings": {
    "PlantaoEntities": {
      "ConnectionString": "CENSORED",
      "ProviderName": "System.Data.EntityClient"
    }
  }
}

But a receives the following message when trying to run the code:

Missing value for AzureWebJobsStorage in local.settings.json. This is required for all triggers other than HTTP. You can run 'func azure functionapp fetch-app-settings ' or specify a connection string in local.settings.json

It's was working before a rebuild solution, and if I try func azure functionapp fetch-app-settings <functionAppName> it try to retrieve the information from the azure portal itself.

like image 429
rubens.lopes Avatar asked Feb 21 '18 13:02

rubens.lopes


People also ask

What is local setting JSON?

The local. settings. json file is where you can define the values for your project in your developer environment. This file must not be added to your source control because it's specific of your own machine.

What is AzureWebJobsStorage?

AzureWebJobsStorage. The name of an application setting that contains the connection string for the Storage account. The AzureWebJobsStorage setting contains the connection string for the Storage account you created with the function app.


2 Answers

I was getting the same error when I was running my Azure Function in my Visual Studio 2019.

enter image description here

I had already set the Copy To Output Directory action to Copy always and I was still getting the same error. The issue is that the Azure Function local.settings.json file doesn't support nested json. You can track this issue here.

I was having values in local.settings.json as preceding.

{
  "IsEncrypted": false,
  "Values": {
    "Custom": {
      "Tickets": {
        "Channels": [
          "One",
          "Two"
        ]
      }
    },
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "ServiceBusConnectionString": ""
  }
}

As you can see that there is an extra nested json (Custom) object inside Values, that is the reason why I was getting this error. To fix this, I had to add a new configuration file called configuration.json and add my custom values there.

"Custom": {
      "Tickets": {
        "Channels": [
          "One",
          "Two"
        ]
      }
    }

The fix is to use either the ConfigurationBuilder or read that file using File.ReadAllText. You can also add the entire JSON as a plain string in the local.settings.json instead of a JSON object.

Hope it helps.

like image 187
Sibeesh Venu Avatar answered Oct 21 '22 08:10

Sibeesh Venu


The solution was to right-click on local.settings.json, go to properties, change "Copy to Output directory" from "Do not copy" to "Copy always". Now the CLI picks up the settings when running from within Visual Studio 2017.

https://github.com/Azure/azure-functions-core-tools/issues/223#issuecomment-326225219

like image 69
rubens.lopes Avatar answered Oct 21 '22 07:10

rubens.lopes