Question

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?

Was it helpful?

Solution 2

I was able to resolve the configuration issue by removing the existing code from my provious answer and replacing it with the following ConfigurationManager implementation:

string MySetting = ConfigurationManager.AppSettings.Get("MyAppSetting");

If works for ASP.NET applications, WinForms applications and WCF Services. I just over-engineered the initial implementation of my class library 3 years ago....

OTHER TIPS

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

It depends on what you're trying to accomplish. On ASP.NET, you'd normally wouldn't use ConfigurationManager for stuff like this, but WebConfigurationManager instead. That said, there's no exact equivalent, since, in reality, the user/roaming/etc stuff that OpenExeConfiguration allows doesn't make sense on a web application.

What do you need it for?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top