IConfigurationSection does not contain a definition for ‘Get’ and no accessible extension method ‘Get’

Today in this article, we will see resolution steps for error IConfigurationsection does not contain a definition for Get.

Issue Description

.NET Core application gives below error at compile-time,

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?)

IConfigurationSection does not contain a definition for Get'

Resolution

The issue is found to exist in the .NET Core base Console or Desktop application (Winforms or WPF) when a user tries to load the configuration needs using ConfigurationBuilder.

The get method is most useful when the user tries to load configuration with an array or list from the settings file.

To fix the issue please add any of the below NuGet packages,

Through CLI

dotnet add package Install-Package Microsoft.Extensions.Configuration.Binder -Version <version>

OR

Using Nuget PMC,

PM > Install-Package Microsoft.Extensions.Configuration.Binder -Version <version>

'IConfigurationSection' does not contain a definition for'Get'

Please note if you are using .NET Host packages etc like Generic Host Builder etc. then, you may need this NuGet package added separately.

This package may need to be added for a non-host console or Windows forms app, where you need to load the configuration using basic non-dependency injection.

Now you shall be able to compile and successfully load the configuration.

Reference :

Did I miss anything else in these resolution steps?

Did the above steps resolve your issue? Please sound off your comments below!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



3 thoughts on “Resolved- IConfigurationsection does not contain a definition for Get

  1. Finally, somebody explained why I had nightmares, I kept asking GPT why I had this error but it gave me nothing helpful 🙂 thanks a lot!

Leave a Reply

Your email address will not be published. Required fields are marked *