ConfigurationBuilder does not contain a definition for SetBasePath | Code2night.com
Code2night
  • Home
  • Blogs
  • Tutorial
  • Post Blog
  • Members
    • Register
    • Login
  1. Home
  2. Blogpost
03 Mar
2021

ConfigurationBuilder does not contain a definition for SetBasePath

8102

Issue-

So , while working with .Net core you often need to read app json file from siteroot to access connection string and other keys available there. So in previous versions we used to use Configuration Builder for reading json file using SetBasePath Method.We used to write

new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appSettings.json").Build();

But the same code becomes non reachable when it comes to .Net core as  you receive error which is shown in below image saying 'ConfigurationBuilder' does not contain a definition for 'SetBasePath' . So will see how to make this work in .Net core 3.1. 

So, This issue is basically because of a missing package in .Net core 3. So for this you have to add Microsoft.Extension.Configuration.json in your project. You can find this package on Nuget package as shown in image.


You can also install this package using Package Manager console using this command. For more reference you can have a look at https://www.nuget.org/packages/Microsoft.Extensions.Configuration.Json and then have a look at installation steps.

Install-Package Microsoft.Extensions.Configuration.Json -Version 5.0.0

So , after you successfully install this package you can check SetBasePath method will start working as expected. You can have a look at below image.


So ,you can follow the steps and this is how you can read app.json file in .Net core 3.1. 

  • |
  • ConfigurationBuilder does not contain a definition for SetBasePath , Reading app json file in dot net core , Appsetting jso , Dot Net Core , c#

Comments

Follow Us On Social Media - Like Us On Facebook

Tags

LinkedinLogin
LinkedinProfile
GetLinkedinProfile
C#
Aspnet
MVC
Linkedin
ITextSharp
Export to Pdf
AspNet Core
AspNet
View to Pdf in Aspnet
Model Validation In ASPNET Core MVC 60
Model Validation
Model Validation In ASPNET Core MVC
Model Validation In ASPNET
Image Compression in AspNet
Compress Image in c#
AspNet MVC
Free Download for New Subscribers!

Subscribe and Click on Verify and Download for download link

Subscribe Now | 670
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading

Welcome To Code2night, A common place for sharing your programming knowledge,Blogs and Videos

  • Panipat
  • info@Code2night.com

Links

  • Home
  • Blogs
  • Tutorial
  • Post Blog

Popular Tags

Copyright © 2023 by Code2night. All Rights Reserved

  • Home
  • Blog
  • Login
  • SignUp
  • Contact
  • Terms & Conditions
  • Refund Policy
  • About Us
  • Privacy Policy
  • Json Beautifier