ConfigurationSection Issue in ASP.NET Core v2.1 RRS feed

  • Question

  • Hello, 

    I have a problem with configurations in ASP.NET Core v2.1. Basically when I use IConfigurationRoot.GetSection on a json configuration then an empty configuration file is returned. 

    Here is the startup constructor.

         public Startup(IHostingEnvironment env)
                CurrentEnvironment = env;
                var builder = new ConfigurationBuilder()
                        .AddJsonFile("config.json", optional: false, reloadOnChange: true);
                 Configuration = builder.Build();

    Here is my ConfigureServices Method.

        // This method gets called by the runtime. Use this method to add services to the container.
           public void ConfigureServices(IServiceCollection services)

    Here is my Build WebHost Method

                .ConfigureAppConfiguration((context, config) =>
                    config.AddJsonFile("config.json", optional: false, reloadOnChange: true);

    And the config.json

                "EmailConfiguration": {
                    "server": "value"
                "ASecondSection": {
                    "SomeKeyWith": "SomeValue"

    Configuration.GetSection("EmailConfiguration") returns an ConfigurationSection with Value null and .GetValue cannot be used on it.

    Configuration["EmailConfiguration:server"] returns value.

    • Moved by CoolDadTx Wednesday, November 14, 2018 4:20 PM ASP.NET related
    Wednesday, November 14, 2018 4:08 PM

All replies