Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find path of active app.config file?

I'm trying to finish this exception handler:

if (ConfigurationManager.ConnectionStrings["ConnectionString"]==null) {     string pathOfActiveConfigFile = ...?     throw new ConfigurationErrorsException(        "You either forgot to set the connection string, or " +        "you're using a unit test framework that looks for  "+        "the config file in strange places, update this file : "         + pathOfActiveConfigFile); } 

This problem seems to only happen to me when I'm using nUnit.

like image 495
MatthewMartin Avatar asked Apr 27 '09 14:04

MatthewMartin


People also ask

Where is app config file located?

The application configuration file usually lives in the same directory as your application. For web applications, it is named Web. config. For non-web applications, it starts life with the name of App.

What is configuration file path?

On assembly, an application's configuration path is set to one or more configuration directories. These directories are set from the Configuration path attributes in module manifest files.

How do I find app config in Visual Studio?

In Solution Explorer, right-click the project node, and then select Add > New Item. The Add New Item dialog box appears. Expand Installed > Visual C# Items. In the middle pane, select the Application Configuration File template.


1 Answers

Try this

AppDomain.CurrentDomain.SetupInformation.ConfigurationFile 
like image 74
Cédric Rup Avatar answered Sep 24 '22 18:09

Cédric Rup