Reputation: 156
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"];
Upvotes: 3
Views: 7904
Reputation: 156
I found the problem.
I defined it in the web.config file in the UI layer.But I called in the unit test method of the Business layer. It worked correctly when called from the UI layer
Upvotes: 1
Reputation: 73
Your code is correct (i have tested), you need to make sure that your app.config file is in your main project (exe).
Upvotes: 3