尝试获取ICacheManager类型的实例时发生激活错误,密钥为“”;高速缓存管理器”;
本文关键字:密钥 错误 管理器 激活 高速缓存 ICacheManager 获取 类型 实例 | 更新日期: 2023-09-27 17:58:19
我在这里似乎遇到了困难,希望任何有能力的人能为我提供帮助。我不太清楚下面的错误信息是什么意思。我正在使用企业模式服务的缓存块,但我一直在遇到下面的问题。我下载了最新版本,并尝试解决这个问题,但我似乎无法确定确切的问题,我需要帮助。提前感谢
Test method WorldBank.Service.Business.UnitTest.TopicsManagerTest.Call_Children_out_of_schoolTest threw exception:
Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type ICacheManager, key "Cache Manager" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager", name = "Cache Manager".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The current type, Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager, is an interface and cannot be constructed. Are you missing a type mapping?
-----------------------------------------------
At the time of the exception, the container was:
Resolving Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager,WuCache
---> System.InvalidOperationException: The current type, Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager, is an interface and cannot be constructed. Are you missing a type mapping?
Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForAttemptingToConstructInterface(IBuilderContext context) in e:'Builds'Unity'UnityTemp'Compile'Unity'Unity'Src'ObjectBuilder'Strategies'BuildPlan'DynamicMethod'Creation'DynamicMethodConstructorStrategy.cs: line 209
BuildUp_Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager(IBuilderContext )
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) in e:'Builds'Unity'UnityTemp'Compile'Unity'Unity'Src'ObjectBuilder'Strategies'BuildPlan'DynamicMethod'DynamicMethodBuildPlan.cs: line 37
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in e:'Builds'Unity'UnityTemp'Compile'Unity'Unity'Src'ObjectBuilder'Strategies'BuildPlan'BuildPlanStrategy.cs: line 43
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:'Builds'Unity'UnityTemp'Compile'Unity'Unity'Src'ObjectBuilder'Strategies'StrategyChain.cs: line 110
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in e:'Builds'Unity'UnityTemp'Compile'Unity'Unity'Src'UnityContainer.cs: line 511
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in e:'Builds'Unity'UnityTemp'Compile'Unity'Unity'Src'UnityContainer.cs: line 515
Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) in e:'Builds'Unity'UnityTemp'Compile'Unity'Unity'Src'UnityContainer.cs: line 173
Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key) in e:'Builds'Unity'UnityTemp'Compile'Unity'Unity'Src'UnityServiceLocator.cs: line 64
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:'Home'Chris'Projects'CommonServiceLocator'main'Microsoft.Practices.ServiceLocation'ServiceLocatorImplBase.cs: line 49
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:'Home'Chris'Projects'CommonServiceLocator'main'Microsoft.Practices.ServiceLocation'ServiceLocatorImplBase.cs: line 53
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService](String key) in c:'Home'Chris'Projects'CommonServiceLocator'main'Microsoft.Practices.ServiceLocation'ServiceLocatorImplBase.cs: line 103
Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory.InnerGetCacheManager(String cacheManagerName) in e:'Builds'EntLib'Latest'Source'Blocks'Caching'Src'Caching'CacheFactory.cs: line 66
Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory.GetCacheManager(String cacheManagerName) in e:'Builds'EntLib'Latest'Source'Blocks'Caching'Src'Caching'CacheFactory.cs: line 53
WorldBank.Service.Business.ResponseManager.Get_w_Utility() in C:'SOOfficialPiece'WorldBank.Service.Business'ResponseManager.cs: line 42
WorldBank.Service.Business.ResponseManager..ctor() in C:'SOOfficialPiece'WorldBank.Service.Business'ResponseManager.cs: line 34
WorldBank.Service.Business.ResponseManager.getResponseObjectJSON(Int32 perpage, Object results, Boolean doDeepRetrieval) in C:'SOOfficialPiece'WorldBank.Service.Business'ResponseManager.cs: line 68
System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
WorldBankBusiness.Topics.TopicsManager.Call_Children_out_of_school(PersonType persontype, EnrollmentType enrollmenttype, String countrycode) in C:'SOOfficialPiece'WorldBank.Service.Business'TopicsManager.cs: line 39
WorldBank.Service.Business.UnitTest.TopicsManagerTest.Call_Children_out_of_schoolTest() in C:'SOOfficialPiece'WorldBank.Service.Business.UnitTest'TopicsManagerTest.cs: line 88
缓存应用程序块需要在app/web.config中提供一些配置信息才能使用(AFAIK,不幸的是,很难找到其他说明文档)。如果没有该配置信息,以下代码将导致抛出与您所看到的相同的异常:
var cm = CacheFactory.GetCacheManager("MyCacheManager");
为了获得CacheManager
,您需要在app.config或web.config中定义CacheManager
:
<configuration>
<configSections>
<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="MyCacheManager">
<cacheManagers>
<add name="MyCacheManager" type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
expirationPollFrequencyInSeconds="60"
maximumElementsInCacheBeforeScavenging="50000"
numberToRemoveWhenScavenging="1000"
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>
</configuration>
添加配置值后,您应该能够从CacheFactory
中获得有效的CacheManager
。这篇文章还有一些可能对你有所帮助的信息。
值得注意的是,如果您正在使用。NET 4.0,对于非web应用程序,您可以使用MemoryCache(在System.Runtime.Caching
命名空间中),它提供了类似的功能,但不需要所有这些配置。对于web应用程序,您当然可以使用System.Web.Caching
中的Cache类。