I am having an intermittent issue that is appearing on one server only, and is causing all MVC pages to fail to load with the error \"An item with the same key has already b
We struggled with this issue for 7 months. The issue seemed to come about when our IIS application pools were automatically recycled. Recycling them again or flicking the web.config usually brought the site back online but it took a lot of digging to find the root cause. After assistance from some external consultants and Microsoft tech support, the issue was traced to a bug in the Telerik library where a key is dynamically added to ConfigurationManager.AppSettings without muti-thread race condition protection. In this instance, we were able to bypass the offending code by adding some entries to the web.config. The issue was identified by Telerik several versions ago so we will update to a newer version for a more permanent fix. The problem comes about if you dynamically update the ConfigurationManager.AppSettings. MS suggestion is as follows:
Change this:
try
{
System.Configuration.ConfigurationManager.AppSettings["YourAppSettingsKey"] = string1;
}
catch(System.Exception)
{
}
to this:
if(ConfigurationManager.AppSettings.Get(key) == null)
{
lock (_lockObj)
{
if(ConfigurationManager.AppSettings.Get(key) == null) // check required inside the lock()
{
ConfigurationManager.AppSettings.Set(key, value);
}
}
}
Hope this helps.