I am 100% certain that the duplicate key error is generated by bad access into the private _myCache
property of the DataCacheFactory
. That property is a Hashtable. Repeated calls to Hashtable.Add("mykey","myvalue");
will generate this same expection that your'e seeing.
I ran multiple tests and calling GetCache("default")
and GetDefaultCache()
back to back doesn't produce the error. It is definitely something odd about how App Fabric is trying to populate that. Here is my code that has never generated this error. I wanted to post for reference incase you can see something that is obviously different from what your code is doing
if (cache == null)
{
if(factory == null)
factory = new DataCacheFactory();
if(string.IsNullOrWhiteSpace(cacheName))
cacheName = ConfigurationManager.AppSettings["APP_FABRIC_CACHE_NAME"];
cache = factory.GetCache(cacheName);
return cache;
}
In the above example, cache
and factory
are private static
versions of their respective types, inside a static class called Cache
.
Hope this helps