3

I am trying to sort out a friends service. Basically it gets into error as soon as I start it in constructor. Here are the code fragments.

public class DefaultCacheManager : ICacheManager
{
    private readonly Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager _cacheManager;

    public DefaultCacheManager()
    {
        //Code blows here
        _cacheManager = CacheFactory.GetCacheManager();
    }

The error I get is below.

Unhandled Exception: System.TypeInitializationException: The type initializer for 'Test.TypeManagement' threw an exception. ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Test.DefaultCacheManager", name ="CacheManager".Exception occurred while: Calling constructor Test.DefaultCacheManager(). Exception is: TypeLoadException - Could not load type 'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer' from assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. ----------------------------------------------- At the time of the exception, the container was:

Resolving Test.DefaultCacheManager,CacheManager Calling constructor Test.DefaultCacheManager() ---> System.TypeLoadException: Could not load type 'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer' from assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
at Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory.InnerGetCacheManager(String cacheManagerName) at Test.DefaultCacheManager..ctor() in c:\Test\CacheManager.cs:line 12 at lambda_method(Closure , IBuilderContext ) at Microsoft.Practices.ObjectBuilder2.DynamicBuildPlanGenerationContext.<>c__DisplayClass1.b__0(IBuilderContext context) at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable1 resolverOverrides)
--- End of inner exception stack trace --- at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable
1 resolverOverrides) at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides) at Microsoft.Practices.Unity.UnityContainerExtensions.Resolve[T](IUnityContainer container, String name, ResolverOverride[] overrides) at Test.TypeManagement.get_CacheManager() in c:\Test\TypeManagement.cs:line 56 at Test.TypeManagement..cctor() in c:\Test\TypeManagement.cs:line 36 --- End of inner exception stack trace --- at Test.TypeManagement.get_ServiceHost() at Test.ThreadManager.Start() in c:\Test\ThreadManager.cs:line 19 at Test.Program.Main(String[] args) in c:\Test\Program.cs:line 14

Any help and direction would be most welcomed.

Config

<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="Cache Manager">
  <cacheManagers>
    <add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000" numberToRemoveWhenScavenging="10" backingStoreName="Data Cache Storage" name="Cache Manager" />
  </cacheManagers>
  <backingStores>
    <add databaseInstanceName="CachingStaging" partitionName="CS" encryptionProviderName="" type="Microsoft.Practices.EnterpriseLibrary.Caching.Database.DataBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching.Database, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="Data Cache Storage" />
  </backingStores>
</cachingConfiguration>
Alag20
  • 161
  • 1
  • 8
  • check this [Link](http://stackoverflow.com/questions/9136/enterprise-library-cachefactory-getcachemanager-throws-null-ref) , i think you are missing configuration. – Srikanth Jul 04 '14 at 12:43
  • Thanks Srikanth. I have already checked my config. Updated the config settings in the question for reference. – Alag20 Jul 04 '14 at 12:48
  • The config references Enterprise Library 5 but it looks like you are loading Enterprise Library 6 assemblies. i.e. `Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0`. In EntLib 6 `EnterpriseLibraryContainer` was removed so the error makes sense. Are you referencing EntLib6 assemblies? The key is to sort out what versions of the assemblies are deployed and loaded by the code and ensure that the version 5 assemblies are the ones loaded (if that is what you want). – Randy Levy Sep 16 '14 at 19:09

0 Answers0