Value of AppDomain.CurrentDomain.SetupInformation.ConfigurationFile changes based on if the file exi

Posted by Dan Neely on Stack Overflow See other posts from Stack Overflow or by Dan Neely
Published on 2010-03-24T14:51:15Z Indexed on 2010/03/24 14:53 UTC
Read the original article Hit count: 885

Filed under:
|

I have a check to make sure the app.config file exists and to report an error if it does not:

System.Windows.Forms.MessageBox.Show(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
if (!File.Exists(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile))
{

    throw new ConfigurationErrorsException("Unable to find configuration file.  File is expected at location:  "
    + AppDomain.CurrentDomain.SetupInformation.ConfigurationFile + "\n");
}

When I build the app.config file in my solution is added to the output directory as AppName.exe.config, and if run from outside visual studio AppDomain.CurrentDomain.SetupInformation.ConfigurationFile contains the path C:...\AppName.exe.config (from within VS it's C:..\AppName.vshost.exe.config). If I delete AppName.exe.config, the value is C:..\Appname.config (no .exe).

I did a bit of farther experimentation, and if Appname.config exists that file will also work to load my setting values.

What's going on here? I need to have everything consistent for error reporting purposes.

© Stack Overflow or respective owner

Related posts about c#

Related posts about app.config