WCF and System.Configuration Namespace

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

Error message:

exePath should be specified if there is no working inside a standalone exe.

Source:

ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 

Has anyone experienced this problem and know how to solve it?

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

+6
wcf system.configuration
source share
3 answers

I managed to solve the configuration problem by removing the existing code from my convincing answer and replacing it with the following ConfigurationManager implementation:

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

If it works for ASP.NET applications, WinForms applications, and WCF services. I just reworked the initial implementation of my class library 3 years ago ....

+3
source share

The bundled assembly of .NET 2.0 is part of the class library that I developed for our corporate library to handle common tasks. It was intended for use in ASP.NET and WinForm applications.

Here is the source code that I used to determine what 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); 
+5
source share

It depends on what you are trying to accomplish. On ASP.NET, you usually did not use the ConfigurationManager for things like WebConfigurationManager. However, there is no exact equivalent, since in fact the user / roaming / etc, which allows OpenExeConfiguration, does not make sense in a web application.

Why do you need this?

+1
source share

All Articles