0

我对这个特定类型的项目和 Ent Lib 5.0 有以下(但非常烦人)问题。

我说它的原因在于它是一个与单元测试项目相关的事实,即相同的代码/配置可以在控制台应用程序中正常工作。

这是代码:

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

这是配置:

         <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>

最后是我只在单元测试项目中得到的异常:

    Activation error occured while trying to get instance of type ICacheManager, key "TestCacheManager"
4

0 回答 0