c# - 企业库异常: Activation error occured while trying to get instance of type ICacheManager, key ?

标签 c# .net caching enterprise-library

使用 .net 3.5 和企业库 5.0。

根据我的研究,我在这里发现了一个类似的问题: Activation error occured while trying to get instance of type ICacheManager, key "Cache Manager" *** 此解决方案没有解决我的问题。

我似乎无法弄清楚,我的配置应该设置正确,但总是出现异常?有人有类似的问题吗?

我在调用缓存管理器时提出了添加缓存管理器和引用的建议:

using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;
.....
....
ICacheManager cm = CacheFactory.GetCacheManager("TrackingCacheManager");

App.config:

<configuration>
    <configSections>
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
        <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>
     <cachingConfiguration defaultCacheManager="TrackingCacheManager">
        <cacheManagers>
            <add name="TrackingCacheManager" type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                expirationPollFrequencyInSeconds="120" maximumElementsInCacheBeforeScavenging="1000"
                numberToRemoveWhenScavenging="10" backingStoreName="NullBackingStore" />
        </cacheManagers>
        <backingStores>
            <add type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                name="NullBackingStore" />
        </backingStores>
    </cachingConfiguration>
    <dataConfiguration defaultDatabase="ConnectionString" />
    <connectionStrings>
        <add name="ConnectionString" connectionString="server=AFS7BCBRNGQ5O0\DEVELOPMENT;database=EITC_RTS;Integrated Security=True"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

我的引用资料:

enter image description here

最佳答案

我的猜测是您已经在域项目的 App.config 中设置了此配置。但是您的主项目有自己的配置文件,必须将此配置复制到该文件中。

例如,如果您的主要项目是一个 webapp,那么它就会有一个 web.config。您添加到 Domain 项目的 App.config 中的缓存配置不会在运行时使用。正在使用的配置来自主项目的配置,在本例中为 web.config。

将您的缓存配置从 Domain App.Config 复制到主配置文件,它将起作用。

关于c# - 企业库异常: Activation error occured while trying to get instance of type ICacheManager, key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23987356/

相关文章:

magento - 如何实现购物车 block 的magento缓存打洞

c# - 在私有(private)空隙之间传递颜色变量

c# - 如果至少有一个任务结束,如何关闭所有任务

c# - Wpf 在主屏幕中启动

sql-server-2005 - 从SQL表缓存计数的最佳方法?

java - 轻量级 Java 对象缓存 API

c# - 使用 IDisposable C# 连接 MySQL

c# - 为什么在 MassTransit 中强烈推荐消息契约接口(interface)?

c# - 如何使用 OpenXML C# 在 Excel 中隐藏工作表?

c# - 如何将西里尔文字音译为拉丁文字