C# 错误:使用Ms Enterprise Library CacheManager时已添加具有相同密钥的项
我的代码正在使用Micosoft.Practices.EnterpriseLibrary.CacheManager。 间歇性问题已报告,错误为“ArgumentException:已添加具有相同键的项”。我无法重现该问题,因此无法提供堆栈跟踪。错误的原因是什么??下面是我的代码,在将密钥添加到缓存之前,它同时具有“锁定”和检查密钥。我怎样才能解决这个问题?此代码位于跨页面使用的公共类文件中。这可能是原因吗 代码-C# 错误:使用Ms Enterprise Library CacheManager时已添加具有相同密钥的项,c#,C#,我的代码正在使用Micosoft.Practices.EnterpriseLibrary.CacheManager。 间歇性问题已报告,错误为“ArgumentException:已添加具有相同键的项”。我无法重现该问题,因此无法提供堆栈跟踪。错误的原因是什么??下面是我的代码,在将密钥添加到缓存之前,它同时具有“锁定”和检查密钥。我怎样才能解决这个问题?此代码位于跨页面使用的公共类文件中。这可能是原因吗 代码- public static CacheManager GetCacheManage
public static CacheManager GetCacheManager(string managerName)
{
if (managers.ContainsKey(managerName))
return managers[managerName];
else
{
lock (managers)
{
try
{
CacheManager cm = CacheFactory.GetCacheManager(managerName);
if (!managers.ContainsKey(managerName))
managers.Add(managerName, cm);
return cm;
}
catch (Exception ex)
{
throw new Exception("There was a problem creating the CacheManager '"
+ managerName + "'. Make sure this CacheManager is properly configured "
+ "in your application settings file. This includes ensuring the right version "
+ "of the Microsoft Enterprise Libraries are used. (The PublicKeyToken is correct.)"
+ ex.Message + ex.StackTrace);
}
}
}
}