ActivationException Activation error occured while trying to get instance of type ICacheManager, key "Cache Manager"

Topics: Caching Application Block
Jul 24, 2013 at 7:46 AM
1:ResolutionFailedException Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager", name = "Cache Manager".
Exception occurred while: Calling constructor Microsoft.Practices.EnterpriseLibrary.Caching.Cache(Microsoft.Practices.EnterpriseLibrary.Caching.IBackingStore backingStore, Microsoft.Practices.EnterpriseLibrary.Caching.Instrumentation.ICachingInstrumentationProvider instrumentationProvider).

Exception is: NullReferenceException - Object reference not set to an instance of an object.

At the time of the exception, the container was:

Resolving Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Cache Manager (mapped from Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager, Cache Manager)
Resolving parameter "realCache" of constructor Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager(Microsoft.Practices.EnterpriseLibrary.Caching.Cache realCache, Microsoft.Practices.EnterpriseLibrary.Caching.BackgroundScheduler backgroundScheduler, Microsoft.Practices.EnterpriseLibrary.Caching.ExpirationPollTimer pollTimer)
Resolving Microsoft.Practices.EnterpriseLibrary.Caching.Cache, Cache Manager
Calling constructor Microsoft.Practices.EnterpriseLibrary.Caching.Cache(Microsoft.Practices.EnterpriseLibrary.Caching.IBackingStore backingStore, Microsoft.Practices.EnterpriseLibrary.Caching.Instrumentation.ICachingInstrumentationProvider instrumentationProvider)
2:NullReferenceException Object reference not set to an instance of an object.
at [   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService](String key)

Message: 0:ArgumentException Delegate to an instance method cannot have null 'this'.
at [   at System.MulticastDelegate.CtorClosed(Object target, IntPtr methodPtr)
Jul 25, 2013 at 3:30 PM
Even i was getting the same error upon using Enterprise library Isolated storage backing store . Tried searching in all forums but could not find a proper response.
Jul 26, 2013 at 7:03 AM
The message usually means that there is some sort of configuration problem. Can you post your configuration and code?

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Jul 26, 2013 at 12:40 PM
<configSections>
  <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, 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="Cache Manager">
<cacheManagers>
  <add name="Cache Manager" type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000"
      numberToRemoveWhenScavenging="10" backingStoreName="NullBackingStore" />
  <add name="Cache Manager" type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000"
      numberToRemoveWhenScavenging="10" backingStoreName="Isolated Storage Cache Store" />
</cacheManagers>

<backingStores>
  <add name="Isolated Storage Cache Store" type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      encryptionProviderName="" partitionName="Cache" />
  <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>__
Jul 26, 2013 at 4:37 PM
The above configuration has 2 cache managers called "Cache Manager". This should result in the error The entry 'Cache Manager' has already been added.

If I change one of the CacheManager names then I can resolve properly.

You didn't post any code so...I'm guessing maybe you are doing something like this?
    var cacheManager = EnterpriseLibraryContainer.Current.GetInstance<CacheManager>();
ICacheManager should be the type to use to retrieve a cache manager:
    ICacheManager cacheManager = EnterpriseLibraryContainer.Current.GetInstance<ICacheManager>();
~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to