Chaka
Chaka

Reputation: 1541

Enterprise library exception: Activation error occured while trying to get instance of type ICacheManager, key?

Using .net 3.5 and Enterprise library 5.0.

From my research, I found a similar issue here: Activation error occured while trying to get instance of type ICacheManager, key "Cache Manager" *** this solution did not fix my issue.

I can't seem to figure it out, my config should be set up correctly, but keep getting the exception? Anyone have similar issues?

I made the suggestion to add cacheManager and reference when I call the cache manager:

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

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

My references:

enter image description here

Upvotes: 3

Views: 12479

Answers (2)

Ajay2707
Ajay2707

Reputation: 5808

I have done silly mistake, but after read above, understand the issue. This is my vb.net code which give me the above error.

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

and in web.config entry is

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

After read just get the issue is CreateDatabase method wants a config entry key as a string and I was given the exact connection string via config entry access. This is my updated code.

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

I was post to somebody help.

Upvotes: 0

dblood
dblood

Reputation: 1778

My guess is that you've setup this configuration in an App.config for your Domain project. But your main project has it's own config file which this configuration must be copied into.

So for example, if your main project was a webapp, then it would have a web.config. The caching configuration you have added to the App.config of the Domain project is not used at runtime. The configuration being used is from main project's config, in this example the web.config.

Copy your Caching configuration from the Domain App.Config to the main config file and it will work.

Upvotes: 4

Related Questions