When i am using a web application, the line of code below
Configuration objConfig = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None);
in class library are giving this error:
"exePath must be specified when not running inside a stand alone exe."
Previously a console application was being used, and the code could access the app.config
. I tried using the System.Web.Configuration
in class library but the dll was not present in the .Net tab for "Add reference".
Kindly help :)
You need to use a different configuration manager in a web context. The following code block shows an example of how to deal with this:
System.Configuration.Configuration configuration = null; if (System.Web.HttpContext.Current != null) { configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); } else { configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With