Developer forum

Forum » Development » Items Code-First with a Server error on creation/edit mode

Items Code-First with a Server error on creation/edit mode

Kevin Steffer
Reply

It's my User Item that gives me the server error on version 8.6.1.14

I have 3 Item Types:

Country:

[Item("Country", "Country"), Category("Dechra")]
	[AreaRule,
		StructureRule(StructureContextType.Pages),
		ParentRule(ParentRestrictionRule.ParentType.RootOfWebsite, ParentRestrictionRule.ParentType.RegularPage),
		SortIndex(101),
		TitlePattern("{{Name}}"),
		TitleField("Name")]
	[CustomizedURLs]
	public class Country : ItemEntry
	{
		public string Name { get; set; }
	}

Department:

[Item("Department", "Department"), Category("Dechra")]
	[AreaRule,
		StructureRule(StructureContextType.Pages),
		ParentRule(ParentRestrictionRule.ParentType.RootOfWebsite, ParentRestrictionRule.ParentType.RegularPage),
		TitlePattern("{{Name}}"),
		SortIndex(100),
		TitleField("Name")]
	[CustomizedURLs]
	public class Department : ItemEntry
	{
		public string Name { get; set; }
	}

User

[Item("User", "User"), Category("Dechra")]
	[AreaRule,
		StructureRule(StructureContextType.Pages),
		ParentRule(ParentRestrictionRule.ParentType.RootOfWebsite, ParentRestrictionRule.ParentType.RegularPage),
		SortIndex(0),
		TitlePattern("{{Name}}"),
		TitleField("Name")]
	[CustomizedURLs]
	public class User : ItemEntry
	{
		[SortIndex(0)]
		public string Name { get; set; }

		[SortIndex(1)]
		public string Username { get; set; }

		[Field("Country", typeof(Dynamicweb.Content.Items.Editors.DropDownListEditor))]
		[OptionItem("Country", "Name", "Id", IncludeChilds = true)]//, IncludeParagraphs = false, ItemSystemName = "Country", NameField = "Name", SourceId = 7, SourceType = Dynamicweb.Content.Items.Metadata.FieldOptionItemSourceType.CurrentArea, ValueField = "Id")]
		[SortIndex(2)]
		public Country Country { get; set; }

		[Field("Department", typeof(Dynamicweb.Content.Items.Editors.DropDownListEditor))]
		[OptionItem("Department", "Name", "Id", IncludeChilds = true)]//, IncludeParagraphs = false, ItemSystemName = "Department", NameField = "Name", SourceId = 8, SourceType = Dynamicweb.Content.Items.Metadata.FieldOptionItemSourceType.CurrentArea, ValueField = "Id")]
		[SortIndex(3)]
		public Department Department { get; set; }
	}

The server i get is this:

[KeyNotFoundException: Den givne nøgle var ikke til stede i ordbogen.]
   System.Collections.Generic.Dictionary`2.get_Item(TKey key) +13772927
   Dynamicweb.Content.Items.Metadata.ItemFieldMetadataLayoutComparer.Compare(ItemField x1, ItemField x2) in E:\Program Files (x86)\Jenkins\jobs\Release DW861\workspace\Dynamicweb\Content\Items\Metadata\MetadataManager.vb:40
   System.Collections.Generic.ArraySortHelper`1.SwapIfGreater(T[] keys, IComparer`1 comparer, Int32 a, Int32 b) +113
   System.Collections.Generic.ArraySortHelper`1.DepthLimitedQuickSort(T[] keys, Int32 left, Int32 right, IComparer`1 comparer, Int32 depthLimit) +102
   System.Collections.Generic.GenericArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer) +433

[InvalidOperationException: Sammenligning af to elementer i arrayet mislykkedes.]
   System.Collections.Generic.GenericArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer) +568
   System.Array.Sort(T[] array, Int32 index, Int32 length, IComparer`1 comparer) +226
   System.Collections.Generic.List`1.Sort(Int32 index, Int32 count, IComparer`1 comparer) +112
   Dynamicweb.Content.Items.Metadata.MetadataManager.GetItemFieldsSortedByLayout(ItemType meta) in E:\Program Files (x86)\Jenkins\jobs\Release DW861\workspace\Dynamicweb\Content\Items\Metadata\MetadataManager.vb:262
   Dynamicweb.Admin.ItemEdit.get_TargetItemFields() in E:\Program Files (x86)\Jenkins\jobs\Release DW861\workspace\Dynamicweb.Admin\Admin\Content\Items\Editing\ItemEdit.aspx.vb:76
   Dynamicweb.Admin.ItemEdit.LoadData() in E:\Program Files (x86)\Jenkins\jobs\Release DW861\workspace\Dynamicweb.Admin\Admin\Content\Items\Editing\ItemEdit.aspx.vb:403
   Dynamicweb.Admin.ItemEdit.Page_Load(Object sender, EventArgs e) in E:\Program Files (x86)\Jenkins\jobs\Release DW861\workspace\Dynamicweb.Admin\Admin\Content\Items\Editing\ItemEdit.aspx.vb:149
   System.Web.UI.Control.OnLoad(EventArgs e) +109
   System.Web.UI.Control.LoadRecursive() +68
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3060

Any ideas what the cause could be?

Kind regards
Kevin


Replies

 
Kevin Steffer
Reply

Weee I found out - it's because I have no Group attribute on my fields

This works!

[Item("User", "User"), Category("Dechra")]
	[AreaRule,
		StructureRule(StructureContextType.Pages),
		ParentRule(ParentRestrictionRule.ParentType.RootOfWebsite, ParentRestrictionRule.ParentType.RegularPage),
		SortIndex(0),
		TitlePattern("{{Name}}"),
		TitleField("Name")]
	[CustomizedURLs]
	public class User : ItemEntry
	{
		[Group("Content"), SortIndex(0)]
		public string Name { get; set; }

		[Group("Content"), SortIndex(1)]
		public string Username { get; set; }

		[Field("Country", typeof(Dynamicweb.Content.Items.Editors.DropDownListEditor))]
		[OptionItem("Country", "Name", "Id", IncludeChilds = true, IncludeParagraphs = false, ItemSystemName = "Country", NameField = "Name", SourceId = 7, SourceType = Dynamicweb.Content.Items.Metadata.FieldOptionItemSourceType.CurrentArea, ValueField = "Id")]
		[Group("Content"), SortIndex(2)]
		public Country Country { get; set; }

		[Field("Department", typeof(Dynamicweb.Content.Items.Editors.DropDownListEditor))]
		[OptionItem("Department", "Name", "Id", IncludeChilds = true, IncludeParagraphs = false, ItemSystemName = "Department", NameField = "Name", SourceId = 8, SourceType = Dynamicweb.Content.Items.Metadata.FieldOptionItemSourceType.CurrentArea, ValueField = "Id")]
		[Group("Content"), SortIndex(3)]
		public Department Department { get; set; }
	}
 
Kevin Steffer
Reply

I've run into a smaller problem.

Since my Department and Country properties are of type Department and Country - the Edit Item doesn't save those properties.
But if I change the two properties to type String it does - but then I have to write some methods to return the Country and Department objects based on the Id of my Country and Department properties returns.

Is this by-design?

 

You must be logged in to post in the forum