The filePath argument for enterpriseLibrary.ConfigurationSource should be a non-relative path?

The MSDN documentation for this item says "The path pointing to the configuration file. This attribute is required if the configuration source is a file." Well, that is pretty obvious.

I tried just setting it to the Path = "enterpriseiselibrary.config" file. The file exists in the root directory of my web application. But when I try to write an exception, I get: "The enterpriseiselibrary.config configuration file was not found." Same thing if I use the relative path "~ / enterpriseiselibrary.config".

So, what's the story with this file path, it should be a hard path (C: ... \ MyApp \ enterpriselibrary.config)? Is there any documentation that I am missing?

+3
source share
2 answers

This is a known bug in EL 5.0: http://entlib.codeplex.com/workitem/26760

Bug fixed in EL 5.0 Additional update 1. There is also a workaround on this error page (code below). I have used the workaround successfully.

workaround:
code:
[Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationElementType(typeof(FileConfigurationSourceElement))]
class FileConfigurationSource : Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource
{

public FileConfigurationSource(string configurationFilepath)
: base(configurationFilepath)
{
}
}
class FileConfigurationSourceElement : Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSourceElement
{
public override Microsoft.Practices.EnterpriseLibrary.Common.Configuration.IConfigurationSource CreateSource()
{
string configurationFilepath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this.FilePath);
return new FileConfigurationSource(configurationFilepath);
}
}
config:
<add name="sourceName" type="YourNamespase.FileConfigurationSource, YourAssembly" filePath ="fileName"/>
+4
source

filePathmay be relative or absolute. If you specify a relative path, then the path is considered relative to the directory AppDomain.CurrentDomain.BaseDirectory. As you have discovered, you cannot use the root path (~ / enterpriseiselibrary.config).

I am not sure why your configuration file was not found; the root of your web application should be basic.

For debugging you can check that:

File.Exists(
    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, 
        "enterpriselibrary.config"))

true. , Enterprise Library .

0

All Articles