Can't get config section after update to ASP.NET Core 2

can definition
can synonym
can noun meaning
can band
can verb
can y

I updated my project from 1.0.0-rc1-final to 1.0.0-rc2-final which is called ASP.NET Core 2 now. This is how I initialize the configuration builder:

var builder = new ConfigurationBuilder().SetBasePath(Environment.GetEnvironmentVariable("ASPNETCORE_CONTENTROOT")).AddJsonFile(file).AddEnvironmentVariables();
IConfiguration configuration = builder.Build();

I know for sure that the initialization is ok because I can do


in the debugger and see all the values in the configuration files in there.

However, if I try to get a whole configuration section like this


it doesn't work. It returns an object no matter what I pass to GetSection. However, the Value field of this object is always null, regardless whether the section exists or not.

Note that this used to work perfectly fine before. Any clues?

It turns out that one can no longer do something like:

var allSettingsInSection = configuration.Get(typeof(StronglyTypedConfigSection), sectionName);

Instead, it has to be done like this now:

IConfigurationSection sectionData = configuration.GetSection(sectionName);
var section = new StronglyTypedConfigSection();

Note that it's necessary to include Microsoft.Extensions.Configuration.Binder in project.json.

Verb Can, lift this piano by myself." The implication here is on whether you have the physical capacity or mental acuity to get the piano lifted. Can definition, to be able to; have the ability, power, or skill to: She can solve the problem easily, I'm sure. See more.

Just a cleaner version of the accepted answer:

public void ConfigureServices(IServiceCollection services)  
    services.Configure<MySettings>(options => Configuration.GetSection("MySettings").Bind(options));


May I? Can I? - English Grammar - English, : a closed metal container that is usually shaped like a cylinder and that holds food or drink. : the food or drink that is in a can. Define can. can synonyms, can pronunciation, can translation, English dictionary definition of can. to be able to, have the power or skill to: I can take a bus to the

In dot net core 2.1 you can do this:

I used nameof here to get the name of the class as a string, rather than use an actual string. This is based on Uwe Kleins reply, it's cleaner.

var myConfigClass = Configuration.GetSection(nameof(MyConfigClass)).Get<MyConfigClass>();

Easily inject your strongly typed configuration as follows:


Use can in a sentence, Can was the leading avant-garde rock group of the 70s. Can experimented with noise, synthesizers, non-traditional music, cut-and-paste techniques, and, most  110 synonyms of can from the Merriam-Webster Thesaurus, plus 97 related words, definitions, and antonyms. Find another word for can. Can: to bring (as an action or operation) to an immediate end.

I am using the GetSection allot and thus I have created an extension method to help me get sections using generics

public static class ConfigurationExtensions
    public static T GetConfig<T>(this IConfiguration config) where T : new()
        var settings = new T();
        return settings;

    public static T GetConfig<T>(this IConfiguration config, string section) where T : new()
        var settings = new T();
        return settings;

CAN (noun) definition and synonyms, Can may refer to: Contents. 1 Containers; 2 Music; 3 Other; 4 See also. Containers[edit]. Aluminum can · Drink can · Oil can · Steel and tin cans · Trash can  A Controller Area Network (CAN bus) is a robust vehicle bus standard designed to allow microcontrollers and devices to communicate with each other's applications without a host computer. It is a message-based protocol , designed originally for multiplex electrical wiring within automobiles to save on copper, but can also be used in many other

Can, VerbEdit. can (third-person singular simple present can, present participle -, simple past could, past participle (obsolete except in adjectival use) couth). Can(stylised as CAN) was a German experimental rockband formed in Colognein 1968 by the core quartet of Holger Czukay(bass, tape editing), Irmin Schmidt(keyboards), Michael Karoli(guitar), and Jaki Liebezeit(drums).

The Official CAN / Spoon Records Website, can meaning: 1. to be able to: 2. used to say that you can and will do something: 3. to be allowed to: . Learn more. We would like to show you a description here but the site won’t allow us.

Can, 1.4Used to indicate that something is typically the case. 'antique clocks can seem out of place in modern homes'. More example sentences. Create beautiful designs with your team. Use Canva's drag-and-drop feature and layouts to design, share and print business cards, logos, presentations and more.

  • Just an update for those who are reading this in 2017 or later. Starting with ASP.NET Core 2.0, addition of this extra NuGet is not required.
  • I've just done a .Net Core 2.1 app and I still need this nuget package, so I don't believe the above comment is correct
  • What Liam said - it's still in the Microsoft.Extensions.Configuration.Binder. But of course you get it in case you are referenceing Microsoft.AspNetCore.App or Microsoft.AspNetCore.All.
  • You can also simply inject your strongly typed configuration like this: var jwtSettingsSection = Configuration.GetSection(nameof(JwtSettings)); services.Configure<JwtSettings>(jwtSettingsSection);
  • I do like var MyConfigClass = Configuration.GetSection(nameof(MyConfigClass)).Get<MyConfigClass>(); to get rid of strings.