1

Closed

Calendar - Cannot Add Events or Parts

description

I am getting an IndexOutOfRangeException when I try to add an Event or a Part to a Calendar that I have created. I am using MVC. I'd love to be able to get this to work because my users would like to have multiple calendars for different sections of the site. Stack trace at the bottom of this post.

STR:
1. Download latest version from GitHub (as of Friday, 27 Jan, 2012)
2. Add Calendar type to MVC project
3. Add an Event or drag a Part onto a child zone of the Calendar (site-wide zones work)
4. Fill in values and Publish
5. This error shows up:

Server Error in '/' Application.

Index was outside the bounds of the array.

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.IndexOutOfRangeException: Index was outside the bounds of the array.

Source Error:


Line 44: public ItemList(IEnumerable<T> items)
Line 45: {
Line 46: Inner = new List<T>(items);
Line 47: }
Line 48:

Source File: D:\temp\n2cms-n2cms-e3f8c9f_20120127\src\Framework\N2\Collections\ItemList.generic.cs Line: 46

Stack Trace:


[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.Array.InternalGetReference(Void* elemRef, Int32 rank, Int32* pIndices) +0
System.Array.SetValue(Object value, Int32 index) +59
NHibernate.Collection.Generic.PersistentGenericBag`1.System.Collections.Generic.ICollection<T>.CopyTo(T[] array, Int32 arrayIndex) +44
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +260
N2.Collections.ItemList`1..ctor(IEnumerable`1 items) in D:\temp\n2cms-n2cms-e3f8c9f_20120127\src\Framework\N2\Collections\ItemList.generic.cs:46
N2.Collections.ItemList..ctor(IEnumerable`1 items) in D:\temp\n2cms-n2cms-e3f8c9f_20120127\src\Framework\N2\Collections\ItemList.cs:16
N2.Definitions.SortChildrenAttribute.ReorderBy(ContentItem item, String sortExpression) in D:\temp\n2cms-n2cms-e3f8c9f_20120127\src\Framework\N2\Definitions\SortChildrenAttribute.cs:72
N2.Definitions.SortChildrenAttribute.ReorderChildren(ContentItem item) in D:\temp\n2cms-n2cms-e3f8c9f_20120127\src\Framework\N2\Definitions\SortChildrenAttribute.cs:56
N2.Persistence.NH.ContentPersister.EnsureSortOrder(ContentItem unsavedItem) in D:\temp\n2cms-n2cms-e3f8c9f_20120127\src\Framework\N2\Persistence\NH\ContentPersister.cs:110
N2.Persistence.NH.ContentPersister.SaveAction(ContentItem item) in D:\temp\n2cms-n2cms-e3f8c9f_20120127\src\Framework\N2\Persistence\NH\ContentPersister.cs:88
N2.Utility.InvokeEvent(EventHandler`1 handler, ContentItem item, Object sender, Action`1 finalAction) in D:\temp\n2cms-n2cms-e3f8c9f_20120127\src\Framework\N2\Utility.cs:445
N2.Persistence.NH.ContentPersister.Save(ContentItem unsavedItem) in D:\temp\n2cms-n2cms-e3f8c9f_20120127\src\Framework\N2\Persistence\NH\ContentPersister.cs:69
N2.Edit.Workflow.Commands.SaveCommand.Process(CommandContext state) in D:\temp\n2cms-n2cms-e3f8c9f_20120127\src\Framework\N2\Edit\Workflow\Commands\SaveCommand.cs:15
N2.Edit.Workflow.Commands.CompositeCommand.Process(CommandContext context) in D:\temp\n2cms-n2cms-e3f8c9f_20120127\src\Framework\N2\Edit\Workflow\Commands\CompositeCommand.cs:24
N2.Edit.Workflow.CommandDispatcher.Execute(CommandBase`1 command, CommandContext context) in D:\temp\n2cms-n2cms-e3f8c9f_20120127\src\Framework\N2\Edit\Workflow\CommandDispatcher.cs:46
N2.Edit.Workflow.CommandDispatcher.Publish(CommandContext context) in D:\temp\n2cms-n2cms-e3f8c9f_20120127\src\Framework\N2\Edit\Workflow\CommandDispatcher.cs:59
N2.Edit.Edit.OnPublishCommand(Object sender, CommandEventArgs e) in D:\temp\n2cms-n2cms-e3f8c9f_20120127\src\Mvc\MvcTemplates\N2\Content\Edit.aspx.cs:119
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +108
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Version Information: Microsoft .NET Framework Version:2.0.50727.5448; ASP.NET Version:2.0.50727.5456

No files are attached

Closed Feb 2 at 7:43 PM by libardo

Gr8


comments

JungleFreak wrote Feb 2 at 7:12 PM

I did a quick test and this seems to have solved the problem. You can close this issue. I'll re-open it if the error occurs again.

Thanks!

libardo wrote Feb 1 at 10:04 PM

I never managed to reproduce this but I have a theory. Could you try this commit and tell if it makes any difference?

https://github.com/n2cms/n2cms/commit/a040d0547457322cb6b97f4930d96ca1cf1c49f6

JungleFreak wrote Jan 30 at 4:48 PM

I debugged the project and stopped the application as it enters N2.Definitions.SortChildrenAttribute.ReorderBy():

private IEnumerable<ContentItem> ReorderBy(ContentItem item, string sortExpression)
{
ItemList temp = new ItemList(item.Children);
temp.Sort(sortExpression);

item.Children.Clear();
foreach (var child in temp)
item.Children.Add(child);

return Utility.UpdateSortOrder(temp);
}

I can get the parts to add by hovering over the 'item' parameter before 'ItemList temp = new ItemList(item.Children);' is executed. Maybe the debugger is forcing a value to come back instead of the result of item.Children being null. After it adds one time, I can then add children at will with no errors.

Hopefully this helps in tracking down what the issue is.