Take the 2-minute tour ×

I'm creating a web application, which calls a DLL to run unit tests, I also have another DLL(DataAccessLayer) which performs connections and performs queries to SQL which references the main DLL. Both the DLLs use the same config file to read settings.

When running application from VS, the application is working fine. However when the web app is deployed to IIS, it seems the DLLs are unable to read the settings from the config file.

After some research I found that I might have to explicitly define the configuration elements in the web.config file, however I don't know how to implement this. Can someone please point me in the right direction?

I'm actually retrieving the settings using the ConfigurationManager with the following code:-

   public string GetValue(string key)
       var appConfig = ConfigurationManager.OpenExeConfiguration("path to dll");
       strKeyValue = appConfig.AppSettings.Settings[key].Value;

       return strKeyValue;


share|improve this question
I guess that the reading of config file is creating confusion, you can clear it out or can get some idea by looking at youtube.com/watch?v=juBDM3fb-i0 –  Nisarg Shah Jan 7 at 10:44
add comment

4 Answers

Use WebConfigurationManager.AppSettings["HelloWorldKey"]; to read AppSettings from the web.config.

share|improve this answer
the settings are not in web.config, they are in a separate App.config which is used by the dll i'm calling. –  krafo Jan 9 '13 at 12:51
Then move them to the web.config - .NET will overwrite the dll settings with the ones from the web.config. Use the app.config as default settings and access them with propterties.settings inside the dll. BTW: configuring a dll isn't neccessary most times - just pass the configuration as parameters in your calls. –  Grumbler85 Jan 9 '13 at 13:14
great thanks mate! –  krafo Jan 10 '13 at 12:38
add comment

Just set all the appSettings values used by the DLL you mention, directly in the web.config PRIOR to deploying the app. You don't need to modify this at run-time (and you shouldn't anyway, since any modification to the web.config will cause the application to restart)

share|improve this answer
so i put all appSettings of my config file in web.config and then in my dll i use the WebConfigurationManager to retrieve the value from the web.config? –  krafo Jan 9 '13 at 13:22
The DLL will automatically read the values from the Web.config. You should use ConfigurationManager.AppSettings on ALL projects. I believe the WebConfigurationManager is deprecated. –  Icarus Jan 9 '13 at 14:00
@Krafo, use System.Configuration.ConfigurationManager.AppSettings[key]. And you have to explicitly add to your dll a reference to System.Configuration (it is normally not included by default in dll projects by Visual Studio). –  Diana Sep 15 '13 at 15:23
add comment

Use following code to access connection string

string filePath= WebConfigurationManager.AppSettings["Pathfile"].ToString();

Web config Fie

       <add key="Pathfile" value="Path to dll"/>
share|improve this answer
add comment

Add the connectionstring or AppSetting or ApplicationSettings used in you app.config into your web.config, I understand this is a manual task but is the only way that the config will read the settings.

share|improve this answer
add comment

Your Answer


