0 votes
by (2.5k points)

The following works in one of my projects : 

Configuration.GetSection("CustomSection").Get<MyConfigType>()

But in another project I get one of two errors : 

'IConfiguration' does not contain a definition for 'Get' and the best extension method

Or a similar error of : 

'IConfigurationSection' does not contain a definition for 'Get' and the best extension method

1 Answer

0 votes
by (2.5k points)
You need to add the nuget package of "Microsoft.Extensions.Configuration.Binder". This always catches me out too.

The reason it may work by default in some projects is likely because they are web projects and the .NET Core Web Project template in Visual Studio has this nuget added by default (Either directly or not). So usually I run into this error when creating console applications or similar where I am adding custom configuration myself.
Welcome to .NET Q&A, where you can ask questions and receive answers from other members of the community.
...