Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Array in Azure Function Application Settings

I'm using appsettings.json for the configuration of my Azure Function (netcoreapp3.1, running on a Windows machine).

In the appsettings.json file there is a array with settings:

{
    "ArraySettings": [
        {
            "ArraySettingProperty1": "ArraySetting1Value1",
            "ArraySettingProperty2": "ArraySetting1Property2"
        },
        {
            "ArraySettingProperty1": "ArraySetting2Value1",
            "ArraySettingProperty2": "ArraySetting2Property2"
        }
    ],
    "SingleSetting": "SingleValue"
}

It works fine if I run the Azure Function locally. But it seems not to work on Azure although the appsettings.json file was deployt and can be found by the Azure Function.

In Startup.cs:

private IConfiguration InitializeConfiguration(IFunctionsHostBuilder functionsHostBuilder)
        {
            ExecutionContextOptions executionContextOptions = functionsHostBuilder
               .Services
               .BuildServiceProvider()
               .GetService<IOptions<ExecutionContextOptions>>()
               .Value;

            return new ConfigurationBuilder()
                .SetBasePath(executionContextOptions.AppDirectory)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddEnvironmentVariables()
                .Build();
        }

This is what I already tried (without success):

  1. Copying the settings to the Values section of the local.settings.json file

  2. Adding the settings to the Application Settings on Azure (with and without commenting out the appsettings.json config) in the following key formats:

    2.1 ArraySettings:ArraySettingProperty1:0

    2.2 ArraySettings__ArraySettingsProperty1__0

    2.3 Values__ArraySettings__ArraySettingsProperty1__0

Why do the array settings work locally but not on Azure? How can I make them work on Azure? Thanks!

like image 968
MatterOfFact Avatar asked Apr 30 '26 16:04

MatterOfFact


1 Answers

Please try setting them like the following in configuration settings in your app service:

Key: ArraySettings__0__ArraySettingProperty1

Value: ArraySetting1Value1

Key: ArraySettings__0__ArraySettingProperty2

Value: ArraySetting1Value2

Key: ArraySettings__1__ArraySettingProperty1

Value: ArraySetting1Value1

Key: ArraySettings__1__ArraySettingProperty2

Value: ArraySetting1Value2

Key: SingleSetting

Value: SingleValue

If your app service is deployed on Windows, you can use : as a delimiter instead of __. However __ works on both Windows and Linux.

like image 141
Gaurav Mantri Avatar answered May 02 '26 07:05

Gaurav Mantri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!