In .net 4 website, I am making use of the Enterprise Library Caching assembly (Microsoft.Practices.EnterpriseLibrary.Caching.dll, version 4.0.0.0).
When I try to get one of my caches using the method
CacheFactory.GetCacheManager("MyCacheManager")
, the .net runtime throws the following exception:
The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager, MyCacheManager]) failed: Object reference not set to an instance of an object. (Strategy type Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy, index 2)
Here is the full stack trace:
==============================================================================
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) at Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing) at Microsoft.Practices.ObjectBuilder2.Builder.BuildUp[TTypeToBuild](IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IReadWriteLocator locator, ILifetimeContainer lifetimeContainer, String id, IConfigurationSource configurationSource) at Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory.GetCacheManager(String cacheManagerName) at MyProduct.MyProductDAL.MyProductDAL..ctor(String connectionString) in C:\Users\Yosief.Kesete\Documents\Visual Studio 2010\Projects\MyProduct\MyProductDAL\MyProductDAL.cs:line 39
================================================================================
I am developing using VS 2010 on a 64-bit Windows 7 Professional PC. My site is hosted in IIS 7.5. I've also added references to the rest of the assemblies that go along with the caching assembly, such as :
Microsoft.Practices.EnterpriseLibrary.Common.dll v4.0.0.0
Microsoft.Practices.ObjectBuilder2.dll v2.1.0.0
Microsoft.Practices.Unity.dll v2.0.414.0
etc...
Can anyone please help me?
Have you wired this up in the web.config? I believe there is a section that must be present in order to find the correct Implementation. The link below shows a loose example.
Moreover, I don't like editing this stuff by hand. The Enterprise Library Configuration Manager will allow you to point and click to wire everything up in a pretty interface.
If you upgrade to version 5.x the user interface for the tool is even better. highly recommended.