【问题标题】:Enterprise library exception: Activation error occured while trying to get instance of type ICacheManager, key?企业库异常:尝试获取 ICacheManager 类型的实例时发生激活错误,密钥?
【发布时间】:2014-07-22 03:32:03
【问题描述】:

使用 .net 3.5 和 Enterprise library 5.0。

根据我的研究,我在这里发现了一个类似的问题: Activation error occured while trying to get instance of type ICacheManager, key "Cache Manager" *** 这个解决方案没有解决我的问题。

我似乎无法弄清楚,我的配置应该设置正确,但不断收到异常?谁有类似的问题?

我建议在调用缓存管理器时添加缓存管理器和引用:

using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;
.....
....
ICacheManager cm = CacheFactory.GetCacheManager("TrackingCacheManager");

App.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>
     <cachingConfiguration defaultCacheManager="TrackingCacheManager">
        <cacheManagers>
            <add name="TrackingCacheManager" type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                expirationPollFrequencyInSeconds="120" maximumElementsInCacheBeforeScavenging="1000"
                numberToRemoveWhenScavenging="10" backingStoreName="NullBackingStore" />
        </cacheManagers>
        <backingStores>
            <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>
    <dataConfiguration defaultDatabase="ConnectionString" />
    <connectionStrings>
        <add name="ConnectionString" connectionString="server=AFS7BCBRNGQ5O0\DEVELOPMENT;database=EITC_RTS;Integrated Security=True"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

我的参考资料:

【问题讨论】:

  • 确保在 App.config 中定义了完整的配置引用跟踪侦听器。有关详细信息,请查看 - stackoverflow.com/questions/7813925/…
  • 日志相关的例子,我需要一个数据访问块的监听器吗?
  • 您是否尝试过从配置中删除PublicKeyToken?您可能拥有具有不同令牌的 DLL,当它们不匹配时,您会遇到异常。
  • 在调用GetCacheManager()时不指定Cache名称是否会得到同样的结果?

标签: c# .net caching enterprise-library


【解决方案1】:

我的猜测是您已经在 App.config 中为您的域项目设置了此配置。但是你的主项目有它自己的配置文件,这个配置必须复制到。

例如,如果您的主项目是一个 web 应用程序,那么它将有一个 web.config。您添加到 Domain 项目的 App.config 的缓存配置在运行时不使用。使用的配置来自主项目的配置,在本例中为 web.config。

将您的缓存配置从 Domain App.Config 复制到主配置文件,它将起作用。

【讨论】:

  • 感谢您的帮助,这正是问题所在!
  • @Chaka 你会把赏金奖励给我吗?
【解决方案2】:

我犯了一个愚蠢的错误,但是在阅读了上面之后,明白了这个问题。这是我的vb.net 代码,它给了我上述错误。

Imports System.Collections
'Imports System.Configuration

Public Class DatabaseLogic
    Public ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("db").ToString()

    Public Function ServerDataMagic(StoredProcedure As String, PDMdata As Hashtable) As DataSet
        Dim db As Database = DatabaseFactory.CreateDatabase(ConnectionString )  'Here  I am getting error.
        Using cmd As DbCommand = db.GetStoredProcCommand(StoredProcedure)
            Try
                db.DiscoverParameters(cmd)
            Catch discover_ex As Exception

            End Try

并且在 web.config 条目中是

<add name="db" connectionString="Database=Dbname;Server=SERVER;uid=sa;pwd=sa@1234" providerName="System.Data.SqlClient" />

读完后发现问题是CreateDatabase 方法需要一个配置条目键作为字符串,我通过配置条目访问获得了确切的连接字符串。这是我更新的代码。

  Dim db As Database = DatabaseFactory.CreateDatabase("db")  'Here I changed the config entry key

我被发帖给别人帮忙。

【讨论】:

    猜你喜欢
    • 2015-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-08
    • 2012-10-21
    • 1970-01-01
    • 2011-02-23
    相关资源
    最近更新 更多