Reputation: 3709
Empty/null value returned when attempting to read from the local.settings.json config file when debugging an Azure Function locally using VS2017 for Mac... after scanning the internet I wasn't able to determine if this is a known issue or if there is a work around. This is how I'm accessing the configuration settings:
ConfigurationManager.ConnectionStrings["connName"].ConnectionString
This works fine if the Function app is debugged on a Windows Machine (same git code base)
Upvotes: 2
Views: 1570
Reputation: 17790
Azure function v2 running on runtime 2.x(.net core) doesn't support ConfigurationManager any more. See Azure Team's reply on github.
When I debug a v2 function on Windows, System.Configuration.ConfigurationErrorsException
thrown. And v1 still works well as you have found.
So as @mariocatch has said, try to read enviroment variables instead.
Two options for you to refer.
Read environment variables directly
string connectionString = Environment.GetEnvironmentVariable("ConnectionStrings:connName");
Add ExecutionContext context
to your function method parameters and read local settings.
[FunctionName("FunctionName")]
public static void Run(...,ExecutionContext context)
{
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
string connectionString = config.GetConnectionString("connName");
.....
}
Upvotes: 2