Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConfigurationManager.AppSettings returning null

I am using ConfigurationManager.AppSettings["smtpHost"] to read a value from the app.config file in my business logic layer, but the value returned is always null, even though the key exists and it has a value, Does any one know why?

App.config file in BLL:

<appSettings>
  <add key="smtpHost" value="smtp.gmail.com" />
</appSettings>

I added the same thing to the web.config file.

And I try to get;

var host = ConfigurationManager.AppSettings["smtpHost"];
like image 234
burak ramazan Avatar asked Feb 03 '26 07:02

burak ramazan


1 Answers

Your code is correct (i have tested), you need to make sure that your app.config file is in your main project (exe).

like image 136
Vladyslav Hrehul Avatar answered Feb 05 '26 21:02

Vladyslav Hrehul