BE2.5 Exception when deleting comments in context

Topics: Business Logic Layer
May 25, 2012 at 12:03 AM
Edited May 25, 2012 at 12:21 AM

Has anyone else run into this issue when attempting to delete comments. In my case this is happening when deleting comments in context (IE, in the comment view where the post is displayed). Here are the details of the exception:

 

 

Collection was modified; enumeration operation may not execute.

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.InvalidOperationException: Collection was modified; enumeration operation may not execute.

 

 

 

Line 752:                this.Post.Comments.Where(comment => comment.Id == new Guid(this.Request.QueryString["deletecomment"])))
Line 753:            {
Line 754:                this.Post.RemoveComment(comment);
Line 755:
Line 756:                var index = this.Request.RawUrl.IndexOf("?");

 

 

Source File: ...\User controls\CommentView.ascx.cs    Line: 754 

Stack Trace: 

[InvalidOperationException: Collection was modified; enumeration operation may not execute.]
   System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) +52
   System.Collections.Generic.Enumerator.MoveNextRare() +9357465
   System.Collections.Generic.Enumerator.MoveNext() +66
   System.Linq.WhereListIterator`1.MoveNext() +137
   BlogEngine.Core.Search.BuildCatalog() in E:\Projects\BlogEngine_25_Release\BlogEngine\DotNetSlave.BusinessLogic\Search.cs:319
   BlogEngine.Core.Search.<.cctor>b__1(Object , EventArgs ) in E:\Projects\BlogEngine_25_Release\BlogEngine\DotNetSlave.BusinessLogic\Search.cs:55
   System.EventHandler`1.Invoke(Object sender, TEventArgs e) +0
   BlogEngine.Core.Post.OnCommentRemoved(Comment comment) in E:\Projects\BlogEngine_25_Release\BlogEngine\DotNetSlave.BusinessLogic\Post.cs:1395
   BlogEngine.Core.Post.RemoveComment(Comment comment) in E:\Projects\BlogEngine_25_Release\BlogEngine\DotNetSlave.BusinessLogic\Post.cs:1170
   UserControls.CommentView.DeleteComment() in ...\User controls\CommentView.ascx.cs:754
   UserControls.CommentView.OnLoad(EventArgs e) in ...\User controls\CommentView.ascx.cs:474
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

 

I cannot seem reproduce this exception locally while debugging, it only seems to happen on our production server. Does anyone have any suggestions?