How to find path of active app.config file?

MatthewMartin picture MatthewMartin · Apr 27, 2009 · Viewed 144.5k times · Source

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.

Answer

Cédric Rup picture Cédric Rup · Apr 27, 2009

Try this

AppDomain.CurrentDomain.SetupInformation.ConfigurationFile