We just started to use Enterprise Library 5 in a project here. One thing that we almost always do is takeout the EntLib configuration out of the App.config/Web.config file. I already did that several times in the past using other version of Enterprise Library with no problem.
What was my surprise today when I tried the same thing I always did with previous version and found that it wasn’t working anymore!
This is the configuration I have in my configuration editor:
I am configuring a Web Application Project and I'm expecting EntLib to find my entlib.config at the root of the website… Wrong!
The problem reside in the fact that the file path resolution logic go through a new method in v5: GetRootedCurrentConfigurationFile, and the current implementation do not handle non rooted path correctly. The problem is that the method try to check the file existence before fixing it when dealing with a non rooted path. Here is the code directly from FileConfigurationSource.cs
private static string GetRootedCurrentConfigurationFile(string configurationFile)
{
if (string.IsNullOrEmpty(configurationFile))
throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "configurationFile");
if (!File.Exists(configurationFile))
{
throw new FileNotFoundException(
string.Format(
CultureInfo.CurrentCulture,
Resources.ExceptionConfigurationLoadFileNotFound,
configurationFile));
}
return
Path.IsPathRooted(configurationFile)
? configurationFile
: Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configurationFile);
}
A proposed fix is already available at CodePlex but it implies to modify the source of EntLib yourself and live with a home, recompiled version of EntLib. That directly means supporting another dependency which is something I don’t want.
Here is the link to the CodePlex page:
FileConfigurationSource::GetRootedCurrentConfigurationFile throws FileNotFoundException on relative path configuration file name
For us, it means that we can’t use Enterprise Library Configuration Sources until this bug is fixed. But… there’s a solution to keep the benefits of having the block configuration in external files. The solution resides in .Net and have been around for a while now: configSource! What we did is use the configSource attribute to point to external files for the desired Enterprise Library sections.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<loggingConfiguration configSource="configs\entlib-logging.config" />
<exceptionHandling configSource="configs\entlib-exception.config" />
</configuration>
This way we can keep the advantage of having our configuration outside the App.config/Web.config until this bug is fixed.
Note: One thing to keep in mind though… You cannot tell multiple configSource to use the same file. This is why I have entlib-logging.config and entlib-exception.config declared in my web.config.
Tags: enterprise library, configuration, bugs