[Solved] Asp.Net Core 3.1 config.GetSection returns null. AppSettings.json null values.

Question: How do you resolve IConfiguration config get value from appSettings.json  that returns a null value?
Login to See the Rest of the Answer

There is a chance you created the appSettings.json file and it is not present in the bin folder. Remember, when the Asp.Net Core Application runs in debug mode, the compiler reads the files from the bin Directory. Follow the steps below to see the bin directory.

Step 1: In Visual Studio Solution Explorer menu bar, click on icon with three document icons.
How to get values from appSettings.json file in Asp.net Core 3.1

Step 2. You will notice a bin folder show up
How to get values from appSettings.json file in Asp.net Core 3.1

Step 3. Right-click on the AppSettings.json file in your project and navigate to "Properties"

Step 4. In the Advanced section, switch from "Do not copy" to "Copy Always" this will include the AppSettings.json file in the bin Directory or Release Directory every time you build your project. 


Change AppSettings.json from Do Not Copy to Copy Always appSettings.json file in Asp.net Core 3.1


Step 5. Build your project and try to retrieve the configuration values from the AppSettings.json again. The values should now be retrieved.


Leave a comment below if this helped you out, so that other Developers can find it useful.

If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

© 2023 - ErnesTech LLC- Privacy