0

I have gone through a couple of similar questions in SO but both are not working as expected in the Azure environment.

I have the following appsettings.json configuration

  {
"Luis": {
    "SubDomain": {
        "AreaOne": {
            "AppIds": {
                "Us": "12345678",
                "India": "567890"
            },
            "APIKey": "xyz123",
            "HostName": "www.example.com"
        },
          "AreaTwo": {
            "AppIds": {
                "Us": "12345679",
                "India": "887890"
            },
            "APIKey": "xyz456",
            "HostName": "www.exampleareatwo.com"
        }
    }
}
}

We are trying to bind it to the following object

public class Luis
{
    public Dictionary<string,SubDomain> SubDomainLuis { get; set; }
}
public class SubDomain
{
    
    public Dictionary<string, string> AppIds { get; set; }
    public string APIKey { get; set; }
    public string HostName { get; set; }
}

We are getting the proper result in the local environment but after hosting the azure app service it shows as null value.

This is the constructor code:

The LuisConfig.SubDomainLuis is always returning a null value in the azure environment.

var LuisConfig = new Luis();
ConfigurationBinder.Bind(configuration.GetSection(nameof(Luis)), LuisConfig);

Startup class:

var config = new Luis();
        Configuration.Bind("Luis", config);
        services.AddSingleton(config);

The directory is always copying the settings file.

enter image description here

These are the questions I have already referred.

  1. Dictionary issue
  2. appsettings mapping
  3. Configuration binding doesn't work
Rajeesh Menoth
  • 1,704
  • 3
  • 17
  • 33

1 Answers1

0

As @ChristianHeld mentioned in the comment the issue is related to the environment appsettings.json. We forget to add environment variable details in the azure configuration. So that is the reason it always points to appsettings.json instead of appsettings.Local.json or appsettings.Dev.json.

ASPNETCORE_ENVIRONMENT is the environment key and value you can add as UAT, DEV, Prod, etc.

Azure AppService -> Configuration

enter image description here

Rajeesh Menoth
  • 1,704
  • 3
  • 17
  • 33