Not reading appsettings.json on server

When I deploy to server my app seems unable to read from the appsettings.json file.

I have this code in my configure method:

var connectionStringPath = "production:pgConString";

if (Env.IsDevelopment())
{
	connectionStringPath = "development:pgConString";
}

container.Register<IDbConnectionFactory>(c =>
	new OrmLiteConnectionFactory(
		AppSettings.Get<string>(connectionStringPath),
		PostgreSqlDialect.Provider));

container.Register<IAuthRepository>(c =>
	new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>()));

container.Resolve<IAuthRepository>().InitSchema();

This works fine locally but it seems that on the server (Ubuntu 18.04) there is an empty string passed and it generates the exception Host Cant Be Null. I replaced the call to the settings file with a hard coded string and the app runs fine but I would much rather use config file.

To try to get some more info on what is going on I followed: https://github.com/Microsoft/MIEngine/wiki/Offroad-Debugging-of-.NET-Core-on-Linux---OSX-from-Visual-Studio

However this doesn’t hit any break points or show locals. It just gives the exception name and says:

No compatible code running

The selected debug engine does not support any code executing on the current thread (e.g. only native runtime code is executing).

Do you have any idea why it is not reading from the appsettings.json file on server or why I am unable to remote debug it with the offroad debugging method?

Why are you using different keys instead of different App Settings for your different environments? e.g. appsettings.json and appsettings.Development.json for Development? So your deployed App would use either settings in appsettings.json or appsettings.Production.json.

I don’t know why you can’t debug your remote .NET Core App, you’d need to ask the .NET Core team.

I wasn’t really thinking to be honest, I just added it in quickly to see if it would work on server. On server it doesn’t read the file at all it seems. I will try specifying a different file.

I will make ticket on github with MS regarding remote debugging not working.

I got debugging working by disabling just my code and require code files to match.

It seems asp.net core is not reading any appsettings files on production so not a SS issue. My apologies.

In case anyone finds this with same problem. For some weird reason asp.net core on Ubuntu 18.04 doesn’t look for the appsettings.json in the app directory by default, it looks in the user directory of user that runs website.

Sounds like a bug with Ubuntu 18.04 as I’ve not seen this behavior in any previous version of Ubuntu or when running with Docker. You may want to report an issue to /aspnet/Home to see if they can explain why it’s not looking for it in the published directory.