i don't seem to be able to read anything from this file in an azure functions when running or debugging a test, however it works fine when debugging the whole application locally.. can anyone explain why at all ?
{
"IsEncrypted": false,
"Values": {
"xyz": 123
}
}
var res = ConfigurationManager.AppSettings.Get("xyz");
ty..
my suspicion is that it is due to the 'debug' being initiated from another project (Test project), and the local.settings.json does not get bundled up with the project being tested ?
Start debugging by attaching to a w3wp.exe remote process At least one breakpoint is setup. Our DLL compile and publish on Azure should be on Debug. The DLL version published on Azure should match the local version.
settings. json file is an analogue of the app. config file in a conventional . Net application. This file contains the configuration settings for your application that can be published to App Settings in your Azure Function App environment.
I added the settings programatically to minify the chances that sensitive data reach version control.
class LocalSettings
{
public bool IsEncrypted { get; set; }
public Dictionary<string, string> Values { get; set; }
}
public static void SetupEnvironment()
{
string basePath = Path.GetFullPath(@"..\..\..\MyAzureFunc");
var settings = JsonConvert.DeserializeObject<LocalSettings>(
File.ReadAllText(basePath + "\\local.settings.json"));
foreach (var setting in settings.Values)
{
Environment.SetEnvironmentVariable(setting.Key, setting.Value);
}
}
Your suspicion is spot on. Only the Azure Functions Runtime Host actually knows to read settings from that file and merge them into the overall AppSettings. When you run in a test project, the Azure Functions Runtime Host is not involved and therefore you don't get access to them.
The simplest way to solve this would be to reflect all the same setting keys/values into your test project's app.config
file under the standard <appSettings>
section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With