Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exePath must be specified when not running inside a stand alone exe

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 :)

like image 535
Pramita Gupta Avatar asked May 23 '13 17:05

Pramita Gupta


1 Answers

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); } 
like image 58
shane Avatar answered Oct 05 '22 19:10

shane