0

I have the following (but very annoying) problem with this particular type project and Ent Lib 5.0.

The reason I am saying it pertains to the fact that it is a Unit Test project related is that the same code/configuration work fine from a Console Application.

Here is the code:

        ICacheManager cm = CacheFactory.GetCacheManager("TestCacheManager");
        cm.Add("max", 1);

Here is the 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>
<dataConfiguration defaultDatabase="Caching" />
<connectionStrings>
 <add name="Caching" connectionString="Data Source=.;Initial Catalog=Caching;Integrated Security=True"
    providerName="System.Data.SqlClient" />
</connectionStrings>
<cachingConfiguration defaultCacheManager="TestCacheManager">
 <cacheManagers>
  <add name="TestCacheManager" 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="TestStore" />
  </cacheManagers>
  <backingStores>
  <add name="TestStore" type="Microsoft.Practices.EnterpriseLibrary.Caching.Database.DataBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      encryptionProviderName="" databaseInstanceName="Caching"
      partitionName="Name" />
  <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>

And then finally the exception that I only get in the Unit Test Project:

    Activation error occured while trying to get instance of type ICacheManager, key "TestCacheManager"
dexter
  • 7,063
  • 9
  • 54
  • 71
  • Where you keep this configuration? In ConsoleApplication? Unit Test project launch special process which can launch unit tests, and it is unrelated to your Console Application config. – outcoldman Apr 08 '13 at 16:27
  • In console application it is an app.config file. So it is for the unit test project as well. Both copy the file in the output directory. – dexter Apr 08 '13 at 16:31
  • 1
    If I remember this correct - it will be loaded only if the name of the config file will match the name of assembly, could you verify that? – outcoldman Apr 08 '13 at 17:21

0 Answers0