[RelatedPosts.cs] An item with the same key has already been added.

Nov 4, 2011 at 10:38 PM
Edited Nov 4, 2011 at 10:41 PM

Hello All,

Keep getting this error:

ScreenShot: http://www.diigo.com/item/image/17qct/pjmk?size=o


An item with the same key has already been added.
Description: An unhandled exception occurred during the execution of the current web request.

Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: An item with the same key has already been added.

Source Error:

Line 245:            sb.Append("</div>");
Line 246:            sb.Append("</div>");
Line 247:            RelatedPostsCache.Add(this.Item.Id, sb.ToString());
Line 248:        }
Line 249:

Source File: c:\HostingSpaces\BrianDavis\programmingsolution.net\wwwroot\App_Code\Controls\RelatedPosts.cs    Line: 247


Query String: http://programmingsolution.net/post.aspx?id=3cda7842-e2eb-47f4-a90c-0c4e387baa94

which redirects to :



Seems to only get this error when bots scan the site.

When manually input the query does not produce error.

Here is the screenshot of the full ELMAH error page:


Seems like BE thinks the bots are trying to add url ?


Brian Davis

Nov 5, 2011 at 6:28 AM

Line 247 where the error is occurring, change that to:

RelatedPostsCache[this.Item.Id] = sb.ToString();

I'll probably check in a change for this.  I need to check out a couple of other issues with related posts.

Nov 5, 2011 at 7:09 AM

The latest check-in, includes this one line code of change, fyi.