FileConfigurationSource not working on web projects
description
<p>I'm using Enterprise Library 5 beta 2. I have moved my loggingConfigurationSection outside of the web.config file. In the web.config file I have added a FileConfigurationSource and the needed section reference. This is working well with app.config files, however on web projects trying to get an instance of LogWriter through the Enterprise Library container throws a FileNotFoundException saying that the file where the FileConfigurationSource points to cannot be found.</p>
<p> </p>
<p>I´m using relative paths in the configuration, so Enterprise Library should devise that and resolve the file starting from my web app root folder. This same configuration is working in other types of projects.</p>
<p> </p>
<p>I have revised the source code for FileConfigurationSource and founded that it checks File.Exists before resolving the relative path. Obviously this is not going to work on web apps, because Environment.CurrentDirectory is set to IIS startup directory, not the web app base directory. However it could do if it combines relative paths with AppDomain.Current.BaseDirectory before checking it the file exists, and also it will work with other types of projects. This is the code in its current form:</p>
<p> </p>
<p>private static string GetRootedCurrentConfigurationFile(string configurationFile)</p>
<p>{</p>
<p> if (string.IsNullOrEmpty(configurationFile))</p>
<p> {</p>
<p> throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "configurationFile");</p>
<p> }</p>
<p> if (!File.Exists(configurationFile))</p>
<p> {</p>
<p> throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.ExceptionConfigurationLoadFileNotFound, new object[] { configurationFile }));</p>
<p> }</p>
<p> if (!Path.IsPathRooted(configurationFile))</p>
<p> {</p>
<p> return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configurationFile);</p>
<p> }</p>
<p> return configurationFile;</p>
<p>}</p>