使用 .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>
我的引用资料:
最佳答案
我的猜测是您已经在域项目的 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/