Enterprise Library not finding config source files in asp.net app

可紊 提交于 2021-01-27 09:35:11

问题


I have my config files in the base directory, set to Content/copy always, in my asp .net web project and when the app runs, it says cannot find the files.

<enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source">
<sources>
  <add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null" />
  <!--<add name="Logging File Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
    filePath="AutomatorConsoleFileFullLogging.config" />-->
  <add name="Logging File Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
    filePath="Logging Configs\AutomatorConsoleFileFullLogging.config" />
  <add name="Exception Handling Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
 filePath="ExceptionHandling.config" />
  <add name="Policy Injection Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
     filePath="PolicyInjection.config" />
</sources>
<redirectSections>
  <add sourceName="Exception Handling Source" name="exceptionHandling" />
  <add sourceName="Logging File Source" name="loggingConfiguration" />
  <add sourceName="Policy Injection Configuration Source" name="Policy Injection Settings" />
</redirectSections>


回答1:


I assume you are getting a message similar to: System.IO.FileNotFoundException: The configuration file cache.config could not be found.

From your configuration I can see that you are using Enterprise Library 5.0 (Build 414). There is an issue in that release with relative paths and FileConfigurationSource in ASP.NET.

Microsoft Enterprise Library 5.0 Optional Update 1 (build 505) has this issue fixed so if you go with the latest version then the issue should be resolved.

Or you could change the config file to use absolute paths. Another fix would be to create your own FileConfigurationSource that correctly resolves the path. You can find source in the comments of the issue report.




回答2:


  <!--<add name="Logging File Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
    filePath="AutomatorConsoleFileFullLogging.config" />-->
  <add name="Logging File Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
    filePath="Logging Configs\AutomatorConsoleFileFullLogging.config" />

Why?

Uncomment the first tag, comment the second tag. I think that should solve your issue?



来源:https://stackoverflow.com/questions/9333215/enterprise-library-not-finding-config-source-files-in-asp-net-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!