Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows service installer not reading App.Config file

I have added App.Config in my project. I have a installer class(ProjectInstaller.cs) which needs to read values from App.config. I am providing the keys . Below is the sample Code :

ConfigurationManager.AppSettings["CONFIG_FILE"]

I am getting null values as per above code ,when invoked in Installer class. But in App.Config file the value for the above key exists.

like image 348
sachin kulkarni Avatar asked Oct 03 '11 10:10

sachin kulkarni


1 Answers

Try:

public string GetServiceNameAppConfig(string serviceName)
{
    var config = ConfigurationManager.OpenExeConfiguration(Assembly.GetAssembly(typeof(MyServiceInstaller)).Location);
    return config.AppSettings.Settings[serviceName].Value;
}
like image 50
Marlon Avatar answered Oct 09 '22 23:10

Marlon