views:

321

answers:

2

While using a third party dll I was getting the following exception - "exePath must be specified when not running inside a stand alone exe" with following trace System.Configuration.ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath).

The reason I found was that it was looking for app.config and I had provided the details in web.config. My question is why does the system.configuration differentiate between web.config and app.config. Any thoughts ?.

+2  A: 

web.config is for your website and web applications only. It stays fixed, i.e. doesn't change its name; it's always called web.config.

app.config is for non-web applications - Winforms, WPF, NT Services etc. This will be renamed into YourApplicationName.exe.config when you build your project. You won't ever find an app.config by that name in an application's directory (or if you do, it will not be used).

Why Microsoft choose to use two different kind of names - I don't know - ask Microsoft.

So you basically just have to know what you're dealing with and provide the information in the correct place.

marc_s
+1, I have added my thoughts regarding the **why** section in my answer below.
Jørn Schou-Rode
+2  A: 

Executables:

Several .NET executables can live in the same directory. As there cannot be two files with the same name in the same directory, the applications must use different names for their main configuration files. The applicationName.exe.config scheme solves this.

Web applications / sites:

.NET web applications are compiled to DLLs, and web sites are usually compiled just-in-time. Hence, there is no "main entry point" in these types of projects. It is possible to create a web project where each page is compiled to its own assembly. Which one is the main assembly? Which assembly should we name the configuration file after

Fortunately, only one web project can be hosted from a single directory, so only one main configuration file is going to live here. This allows for the main configuration file name to be picked by convention, and that file name happens to be web.config.

Jørn Schou-Rode