Recently I was working on a project where we wanted to use In-Role Windows Azure Caching. We ran into a number of issues while making it work. In this blog post, I will share that experience.
Shorter Version (Tl;dr;)
Two things you would need to keep in mind:
- If the caching is not working at all, see if you’re using Windows Azure Caching package 126.96.36.199. If that’s the case, make sure you’re using Windows Azure SDK Version 2.1.
- If the caching is working intermittently, its time to update your Visual Studio to the latest version. At the time of writing of this blog, “Update 3” of Visual Studio 2012 was the most latest version.
- Update: This is only true for Windows 8 machines. Check if Hyper-V is enabled on your Windows 8 machine. In my experience, having Hyper-V enabled messes up caching big time! Uninstalling the service (Programs & Features -> Turn Windows Feature On/Off) has positive impact on caching (don’t ask me why, because I don’t know :))
Now for my (in)famous longer version of the blog post .
Problem 1: Caching Just Won’t Work
So for our project we started implementing Windows Azure Caching. We went through the guides available on Windows Azure website and based on that built a small prototype. The code to initialize the cache was really simple:
cache = new DataCache(nameOfCache);
When we ran the application, it just didn’t work. All we got was “No such host is known” error. Interestingly one of my team member had an other application which used cache and that worked flawlessly. We were completely baffled. Same piece of code worked in one cloud project but didn’t work in other. Him and an other colleague of mine looked deeply and found that the project where it worked was using Windows Azure Caching library 188.8.131.52 while the version of the library that didn’t work was using Windows Azure Caching library 184.108.40.206. We were using Windows Azure SDK version 2.0. They then looked at the package description on Nuget and found that version 220.127.116.11 will only work with SDK version 2.1.
More information about this can be found on these threads on StackOverflow:
So we downgraded the Windows Azure Caching library to version 18.104.22.168 and our caching started working properly. So far so good!
Problem 2: Caching Worked Intermittently
This was a really ridiculous problem . So we wrote some code and when my colleague ran the code, it worked perfectly fine on his computer however when I ran the same code on my computer, it ran for a little bit and then caching started throwing all kinds of exceptions. Some of the errors I encountered were:
iisexpress.exe Information: 0 : INFORMATION: <DistributedCache.ClientChannel.22.214.171.124.1:54346; 127.255.0.1:20004> SocketException errorcode:10060 message System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond at System.Net.Sockets.Socket.EndReceive (IAsyncResult asyncResult) at Microsoft.ApplicationServer.Caching.TcpSocketChannel.AsyncReceiveCallback(IAsyncResult result)
iisexpress.exe Information: 0 : INFORMATION: <DistributedCache.ClientChannel.126.96.36.199.1:54346; 127.255.0.1:20004> Aborting channel 127.0.0.1:54346; 127.255.0.1:20004. iisexpress.exe Warning: 0 : WARNING: <SimpleSendReceiveModule> DeadServerCallback Called, Server URI: [net.tcp://127.255.0.1:20004], Underlying exception -
I searched all over the Internet and found that there were number of folks who were facing similar kind of problem. However none of them found a solution to the problem.
I then approached Windows Azure Caching team and they have been extremely helpful. They worked diligently with me on getting this issue resolved. We went back and forth however nothing was coming out of it. All the while the code continued to work on my colleague’s machine. This made me realize that there is something wrong with my machine. We compared both machines and found that both of us were running different versions of Visual Studio 2012 and Windows 8 operating system. Since we were not getting anywhere, I decided to repave my machine.
So I had Windows 8 Enterprise Edition and Visual Studio 2012 Premium Edition and my colleague had Windows 8 Pro and Visual Studio 2012 Ultimate. I decided to repave my machine to the same in the hope that things might work. Spent about a couple of hours and got everything installed. Ran the application, still same result . Then I realized my colleague had “Update 3” of Visual Studio 2012 applied as well which I didn’t. So I thought – what the hell, let’s try that as well.
Guess what – once I updated Visual Studio to the latest update, magically things started working . I know, I know … it’s a lame solution but hey, it worked for me. You may want to try that.
If your computer’s operating system is Windows 8/8.1, another thing you might want to check is if Hyper-V component is installed on your computer. You can do that by going into “Control Panel” –> “Programs and Features” –> “Turn Windows features on or off”. In my experience (and some other folks), having this service installed messes up caching big time. I think this gets installed when you install tools for Windows Phone 8 development. Uninstalling this service has a positive impact on caching. To uninstall, just uncheck all the Hyper-V related checkboxes. You would need to reboot your computer after you do that.
To summarize, if caching doesn’t work at all look at caching library/SDK version mismatch and if caching works intermittently, consider upgrading your Visual Studio to the latest version and uninstalling Hyper-V from your Windows 8 machine. Last few days have been quite frustrating and unproductive and if you’re facing similar problems, I hope that one of these solutions work for you and you don’t have to go through the same ordeal as I did.
Hope this helps.