Adding Windows Azure Caching Crashes Visual Studio 2012 with the nullatation_ argument of the datacachefactory
I added the Windows Azure Cache 1.8.0 nuget package for my solution, but it ends up crashing Visual Studio when loading the project. I found that I could "prevent" the crash by removing the DLLs from the bin folder and then again when visual studio adds them back to the trash while the project is loading.
Removed DLLs:
Microsoft.ApplicationServer.Caching.AzureClientHelper.dll
Microsoft.ApplicationServer.Caching.AzureCommon.dll
Microsoft.ApplicationServer.Caching.Client.dll
Microsoft.ApplicationServer.Caching.Core.dll
When I look at the event viewer for visual studio crash, I get this:
Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentNullException
Stack:
at System.Threading.Monitor.Enter(System.Object)
at Microsoft.ApplicationServer.Caching.DataCacheFactory.Close()
at Microsoft.ApplicationServer.Caching.DataCacheFactory.Finalize()
I'm not sure why VS is running the DLL while the project is loading, but I'll admit I'm not an expert on this.
Basically I followed the process outlined on this page to add a cache role for caching: http://www.windowsazure.com/en-us/develop/net/how-to-guides/cache/
I tried to uninstall and reinstall the package by uninstalling and reinstalling the Visual Studio SDK (Oct 2012) but the problem came back.
Also, I don't have an application server installed.
Thanks in advance for your help!
source to share
If anyone else comes across this issue, I am providing what seems to work for me here.
To get visual studio to load the project, I removed the DLL from the project. I also deleted them as the project was loaded and VS put the dll back in the bin folder.
I removed the DLL references. Then I removed my code which was using datacachefactory.
In the end, I believe it was caused by misuse of the cache in my code that I followed. I was able to fix using it, build a solution, and put all DLLs back into the project.
Previously, the datacache object was not static.
here's my correct use of datacache factory:
using System;
using Microsoft.ApplicationServer.Caching;
namespace WebRole1.Classes
{
public class AzureCache
{
public static DataCache cache { get; set; }
public static DataCacheFactory dataCacheFactory { get; set; }
public AzureCache()
{
if (cache == null){
DataCacheFactoryConfiguration cfg = new DataCacheFactoryConfiguration();
cfg.AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, "CacheWorkerRole1");
dataCacheFactory = new DataCacheFactory(cfg);
cache = dataCacheFactory.GetDefaultCache();
}
}
public void Add(string item, object value)
{
cache.Add(item, value);
}
public void Add(string item, object value, TimeSpan timeout)
{
cache.Put(item, value, timeout);
}
public object Get(string item)
{
return cache.Get(item);
}
public TimeSpan TimeRemaining (string item)
{
DataCacheItem DCitem = cache.GetCacheItem(item);
return DCitem.Timeout;
}
public void Flush()
{
cache.Clear();
DataCacheFactory cacheFactory = new DataCacheFactory();
cache = cacheFactory.GetDefaultCache();
}
}
}
source to share
We may need to capture a dump of the visual studio process (devenv.exe) to find out what is causing this exception. You can use debugdiag (" http://www.microsoft.com/en-us/download/details.aspx?id=26798 ") to capture the dump. You may need to use Microsoft Support Services (" http://www.windowsazure.com/en-us/support/contact/ ") to investigate further, as the exception comes from the cache code itself.
source to share
This is not a purely Visual Studio issue. I get it during my webrole startup. Check out this other article .
source to share