ConfigurationBuilder does not contain a definition for SetBasePath or AddJsonFile

Issue Description

.NET Core application gives below error at compile time,

ConfigurationBuilder‘ does not contain a definition for ‘SetBasePath‘ and no accessible extension method ‘SetBasePath’ accepting a first argument of type ‘ConfigurationBuilder’ could be found (are you missing a using directive or an assembly reference?)

ConfigurationBuilder does not contain a definition for SetBasePath or AddJsonFile

Resolution

The issue is found to be existing in .NET Core base Console or Desktop application (Winforms or WPF) when configuration needs to be loaded using ConfigurationBuilder.

SetBasePath sets the FileProvider for file-based providers to a PhysicalFileProvider with the base path.

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

Through CLI

dotnet add package Microsoft.Extensions.Configuration.Json --version 3.1.8

OR

Using Nuget PMC,

PM > Install-Package Microsoft.Extensions.Configuration.Json -Version 3.1.8

ConfigurationBuilder does not contain a definition for SetBasePath or AddJsonFile

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

Did I miss anything else in these resolution steps?

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

Happy Coding !!

Reference :



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.



4 thoughts on “ConfigurationBuilder does not contain a definition for SetBasePath or AddJsonFile

Leave a Reply

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