I have this code to load a config file and read all the values and it works fine when running the application but of course fails on team city because the appdomain\'s base
how about:
Application.StartupPath;
differents ways to get the base directory
AppDomain.CurrentDomain.BaseDirectory
Directory.GetCurrentDirectory()
// not guaranteed to work on Mobile application
Environment.CurrentDirectory
// this calls Directory.GetCurrentDirectory()
this.GetType().Assembly.Location
// Assembly.location
Application.StartupPath
// for windows forms apps
Application.ExecutablePath
// same as Application.StartupPath
So it sounds/looks like you're attempting to obtain the configuration file for an assembly. The following should accomplish that task by accessing the 'Location' property of the assembly and using it to retrieve the configuration path:
static string GetConfigFileByType(Type type)
{
Configuration config =
ConfigurationManager.OpenExeConfiguration(type.Assembly.Location);
if (config.HasFile)
return config.FilePath;
throw new FileNotFoundException();
}