'C# configuration getsection returns null even when section exists

In the following line of code the 'loggingConfig' is returning null and getting the specified exception. The config section is available in appsettings.json. but still having this error

var loggingConfig = appConfiguration.GetSection("logging")?.Get<LoggingConfig>();
if (loggingConfig == null)
   throw new ConfigurationErrorsException("logging Config not specified");

Model

public class LoggingConfig
{
    public string LogFilePath { get; set; }
    public string ApplicationName { get; set; }
}

appsetting.json

{
    "logging": {
        "logFilePath": "log/log-.txt",
        "applicationName": "API",
        "IncludeScopes": false,
        "Debug": {
            "LogLevel": {
                "Default": "Error"
            }
        }
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source