.NET Core json settings and environment variable

Today we deployed .NET Core application on a test machine and then configured the application as environmental variable in the system.

When we started the command line application, it couldn't find 'settings.json' file for reading the configuration.

This happens because the application looks for it on the relative path where the command was executed.
For example application is in C:\Temp\tool.exe and you run enter 'tool' while in 'C:\Users\hvetter', the application will start but will not found your settings file because it searches it in 'C:\Users\hvetter' folder instead of 'C:\Temp\'.

This is the code we used to load the settings file and the output in the Commandline.

SETTINGS_FILE_NAME is a constant and equals 'settings.json'.

It searched 'settings.json' file in relative wrong folder.

 

I changed the code to this for testing and added the output to show what happened.

 

Recap: Don't use relative paths in .Net Core for loading your settings :)


Posted Oct 19 2016, 05:19 PM by Holger Vetter
Filed under:
developers.de is a .Net Community Blog powered by daenet GmbH.