Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF and System.Configuration namespace

I received an error when an referenced .NET Framework 2.0 assembly tried to execute the following line of code in an IIS hosted WCF service:

Error Message:

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

Source Code:

ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

Has anyone experienced this issue and do they know how to resolve it?

EDIT: My question is, what is the best way to open a configuration file (app.config and web.config) from a WCF service that is backwards compatible with a .NET 2.0 assembly?

like image 708
Michael Kniskern Avatar asked Oct 24 '08 23:10

Michael Kniskern


1 Answers

The referenced .NET 2.0 assembly is part of a class library I developed for our enterprise library to handle common taskes. It was intended to be used in ASP.NET and WinForm applications.

Here is the source code I used to determine which type of configuration file to open:

//Open app.config or web.config file
if (HttpContext.Current != null)
    this.m_ConfigFile = WebConfigurationManager.OpenWebConfiguration("~");
else
    this.m_ConfigFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
like image 92
Michael Kniskern Avatar answered Oct 24 '22 22:10

Michael Kniskern