Pages

Monday, September 1, 2014

Unresponsive DataCacheFactory Constructor Initialization

Hey folks,

This was one of the most strange issue I saw today and it is with Microsoft Azure Managed Cache Service APIs.

What was the issue?

We were using Azure managed cache 2.3.1 APIs and everything was set including changes needed in the configuration files.

Here is what typical snippet to initialize the cache factory looks like


static DataCacheFactoryConfiguration cacheFactoryConfiguration = new DataCacheFactoryConfiguration("default");
static DataCacheFactory cacheFactory = new DataCacheFactory(cacheFactoryConfiguration);


The line 2 in above snippet was the issue. As soon as the compiler used to hit the line which actually initializes the DataCacheFactory object from config file - compiler never returned.

In the very first line of this post I mentioned a word strange because - the snippet above worked on each machine (windows 8 / windows 8.1) with no issues however there was a colleague of mine who was facing the problem who had exact same configuration as that of other machines.
Adding more suspense to the scenario, this only didn't work with the web application. When we tried creating a quick console application pointing to the same cache service on same machine - it worked. interesting the world of programming, isn't it?

 What is the solution?

Well, after long search on this, mostly found links about best practices of using DataCacheFactory class but nothing near the actual issue. At one point - started feeling that are we the ONLY guys in entire universe who are facing this real strange issue? but .. there is one thing you can keep doing and that is keep trying.. and we headed towards searching more on this by altering keywords here and there and then we found something

found a post of stackoverflow in which the guy described about exact same issue and solution too, but the real reason behind this error is still unknown to me ( or to the post owner too). If anyone knows - feel free to leave a comment.

 There are two components which you might find installed on your machine.i.e
1. IIS Express Application Compatibility Database for x64 and
2. IIS Express Application Compatibility Database for x86

All you need to do is, uninstall those, restart your visual studio and you are done.

[Adding further notes which were not there in the post mentioned above]
After this, if you start facing the error -
Specified argument was out of the range of valid values. parameter name site.

Don't get panic, simply install IIS on your local computer. Here is how you can do this
Open Control Panel > Turn Windows features on or off  > Check Internet Information Services and click ok.

Restart visual studio and you are good to go.

Hope this works for you and saves your efforts of searching solution for this strange issue.

2 comments:

  1. Hi Bhushan do you have cache configuration in config file or creating configuration programatically?ideally it should be in config file. DataCacheFactory is an expensive object to create due to what it does i.e. makes a network connection to each server in the cluster. move it to Application_start.

    ReplyDelete
  2. Yes Anil, it's in the configuration file and you are right it is indeed a very expensive object.

    ReplyDelete