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 solution, the app.config file in 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:\path\AppName.exe.config (from within VS it's C:\path\AppName.vshost.exe.config). If I delete AppName.exe.config, the value is C:\path\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.