2

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!

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

Comments

1

This works:

public class MyOptions
{
      public List<string> MyArray { get; set; }
}

// local.settings.json:
{
  "IsEncrypted": false,
  "Values": {
    "MyOptions__MyArray__0": "foo",
    "MyOptions__MyArray__1": "bar"
  }
}

// In startup.cs:
builder.Services.Configure<MyOptions>(configuration.GetSection("MyOptions"));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.