This morning I was working on an ASP.Net Core Controller
that's housed in a .Net Core library project. I was wanting to load up some settings from a configuation file and ran into the following error message:
Error CS1061
'IConfigurationSection' does not contain a definition for 'Get' and no accessible extension method 'Get' accepting a first argument of type 'IConfigurationSection' could be found (are you missing a using directive or an assembly reference?)
Normally the Intellisense in Visual Studio is good at recommending which NuGet package is missing but this morning it did not have one. After looking through the docuementation on Microsoft's site it appears that package I was looking for was Microsoft.Extensions.Configuration.Binder
. After adding the NuGet package and then including a few using
statements I was able to load my settings.
C# Usings
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Binder;
C# to load my settings
var settings = Configuration.GetSection("Settings").Get();