编程语言
首页 > 编程语言> > c#-企业库异常:尝试获取ICacheManager类型的实例的密钥时发生激活错误?

c#-企业库异常:尝试获取ICacheManager类型的实例的密钥时发生激活错误?

作者:互联网

使用.net 3.5和Enterprise Library 5.0.

从我的研究中,我在这里发现了类似的问题:
Activation error occured while trying to get instance of type ICacheManager, key “Cache Manager” ***此解决方案无法解决我的问题.

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

我建议在调用缓存管理器时添加cacheManager和引用:

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>

我的参考资料:

解决方法:

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

因此,例如,如果您的主项目是一个webapp,则它将具有一个web.config.您添加到Domain项目的App.config中的缓存配置在运行时不使用.使用的配置来自主项目的配置,在本示例中为web.config.

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

标签:caching,enterprise-library,c,net
来源: https://codeday.me/bug/20191029/1960416.html