Skip to content
January 31, 2008 / kiranpatils

Facing Problem in Enterprise Library-Caching Application Block+WCSF

Yesterday i have wasted[or invested] my whole day in solving the error…hoohhh..

What i want to do?

I want to use Caching Application Block with WCSF. means when user clicks on submit i have to Cache that page using CAB of MEL. it seems simple but i am facing problem in implementing it.

Problem I was facing

When i calls CacheManager _cacheManager = CacheFactory.GetCacheManager();

it gives me error. I have pasted stack trace here.

Stack Trace is as under:
Could not load file or assembly Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
System.TypeInitializationException was unhandled by user code
Message=”The type initializer for ‘Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory’ threw an exception.”
Source=”Microsoft.Practices.EnterpriseLibrary.Caching”
TypeName=”Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory”
StackTrace:
at Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory.GetCacheManager()
at Consensus.Net.Framework.Common.Caching.Cache.SetCache(String key, Object value) in C:\Latest Poc [Working Folder]\Consensus\Source\Consensus.Net.Framework\Consensus.Net.Framework\Caching\Cache.cs:line 38
at Consensus.Net.Web.Customer.CustomerController.cachepage(Booker booker) in C:\Latest Poc [Working Folder]\Consensus\UI\Consensus.Net.Web\Customer\CustomerController.cs:line 69
at Consensus.Net.Web.Customer.Views.DefaultViewPresenter.CachePage() in C:\Latest Poc [Working Folder]\Consensus\UI\Consensus.Net.Web\Customer\Views\DefaultViewPresenter.cs:line 64
at Customer_Default.btnSubmit_Click(Object sender, EventArgs e) in c:\Latest Poc [Working Folder]\Consensus\UI\Consensus.Net.Web\WebSites\DevelopmentWebsite\Customer\Default.aspx.cs:line 138
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

I have searched on google and blog also…But i am unable to find it out. and no help on codeplex also.. i have invested almost one day for it and i don’t want that you people also waste for the same problem

So here’s the solution:

Solution may look so simple but it is working fine and taken much of my time so its most precious for me.
Just add Microsoft.Practices.EnterpriseLibrary.Common.dll(i have it at “C:\Program Files\Microsoft Enterprise Library 3.1 – May 2007\Bin”) Version: 3.1.0.0 to GAC[if you don’t know how to add it refer below step or Add it..].

Adding An Assembly to GAC
  1. Click the Assembly Cache node of the console tree. Alternately, you can click the Manage the Assembly Cache link in the pane on the right.
  2. Click the View List of Assemblies in the Assembly Cache link in the pane on the right.Alternately, you can right-click the Assembly Cache node, point to View on the shortcut menu, and select Assemblies.

    The tool displays all assemblies in the Global Assembly Cache in the pane on the right. The tool also displays all native image versions of assemblies in the cache. Native images are versions of assemblies that have been pre-compiled to native code using the Native Image Generator (Ngen.exe).

  3. To delete an assembly from the cache, right-click the assembly name in the pane on the right and choose Delete from the shortcut menu.
  4. To add an assembly to the cache, right-click the Assembly Cache node and choose Add from the shortcut menu. The tool displays the Add an Assembly dialog box. Navigate to the assembly to add.

That’s it .

Happy Caching!!!.

-Kiran Patil

7 Comments

Leave a Comment
  1. Alex U. / Mar 7 2008 6:02 pm

    I was having the same problem with Enterprise Library Data Application Block in SCSF, after installing VS 2008 on my machine.

    The solution was the same, adding Microsoft.Practices.EnterpriseLibrary.Data.dll in GAC, and checking to have the same Version, Culture and Token in my application app.config, where I was using it.

    This article helped me fix my issue and learn about assemblies!

    Thank you

  2. Ramesh / Nov 12 2008 3:58 pm

    I too having the same problem, I tried the same way, but didn’t worked out.
    I placed Common and Cache both dlls to GAC. But still I am having the same problem.
    My environment is : I am hosting WCF service in IIS5.1, then I am getting this problem, but in working environment I don’t have any problem.

    Here is my config file at server side (in app.config) accessible to class library:

    Here is my service code accessing the cache :
    public DistributionService()
    {
    connString = Settings.CONNECTIONSTRING;
    connection = new OracleConnection(connString);
    cacheManager = CacheFactory.GetCacheManager(“Loading Scenario Cache Manager”);
    resMgr = new ResourceManager(typeof(DistributionServiceResource));
    }

    Instead of empty GetCacheManager I am accessing my own defined cache object.

    What’s the problem in my config file? I really stuck-up with this problem from the last 2 days…

    Regards,
    Ramesh T

  3. Ramesh / Nov 12 2008 3:59 pm

    I too having the same problem, I tried the same way, but didn’t worked out.
    I placed Common and Cache both dlls to GAC. But still I am having the same problem.
    My environment is : I am hosting WCF service in IIS5.1, then I am getting this problem, but in working environment I don’t have any problem.

    Here is my config file at server side (in app.config) accessible to class library:

    Here is my service code accessing the cache :
    public DistributionService()
    {
    connString = Settings.CONNECTIONSTRING;
    connection = new OracleConnection(connString);
    cacheManager = CacheFactory.GetCacheManager(“Loading Scenario Cache Manager”);
    resMgr = new ResourceManager(typeof(DistributionServiceResource));
    }

    Instead of empty GetCacheManager I am accessing my own defined cache object.

    What’s the problem in my config file? I really stuck-up with this problem from the last 2 days…

    Regards,
    Ramesh T

  4. Codegoblin / Jan 22 2009 9:39 am

    I solved it by recompiling the source code for caching assembly and using that dll. Then change the entry in app.config for PublicKeyToken=null” for caching assembly . With this change it all worked nice. Thanks to point out that one of the dll is signed and other one is not.

  5. kafe / Jul 5 2009 11:30 am

    same bug, but solution does not work for me
    MS enterprise library is a really poor, and bad thing.
    Had any team erote this in a corp. evviornment..whole team wud have been fired.

  6. Birendra / Jun 1 2010 3:37 pm

    Remove all existing caching refrences and add again

    Microsoft.Practices.EnterpriseLibrary.Common.dll

    Microsoft.Practices.EnterpriseLibrary.Caching.dll

    If you decide to use the database as a caching store, you also need to add a reference to the Data Access Block (the Microsoft.Practices.EnterpriseLibrary.Caching.Data.dll).

    Microsoft.Practices.ObjectBuilder2.dll

Trackbacks

  1. Windows Vista News

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: