Developer forum

Forum » Development » Items - Code first IList property

Items - Code first IList property

Morten Bengtson
Reply

I'm having some problems with custom items that has properties of type IList. The items work fine on create, view, update, delete... but I get an exception when I try to copy a page containing an item with IList properties.

 

The two properties on the item...

 

[Field("Categories", typeof(CheckboxListEditor<>))]
public IList<string> Categories { get; set; }
        
[Field("Tags", typeof(TagListEditor))]
public IList<string> Tags { get; set; }

 

TagListEditor is a custom Editor...

[Editor("Tag list")]
public class TagListEditor : ListEditor<IEnumerable<string>>
{
...
}

 

If you could provide some sample code for a custom item with IList properties that actually works it would be very much appreciated ;-) 

 

[InvalidCastException: Invalid cast from 'System.String' to 'System.Collections.Generic.IList`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.]
   System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) +10578274
   System.String.System.IConvertible.ToType(Type type, IFormatProvider provider) +8
   System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +10625268
   System.Convert.ChangeType(Object value, Type conversionType) +32
   Dynamicweb.Extensibility.AddInManager.SetAddInPropertyValue(Object instance, String PropertyName, Object PropertyValue, Boolean tryConvert) +175
   Dynamicweb.Content.Items.ItemEntry.DeserializeFrom(IDictionary`2 dictionary) +108
   Dynamicweb.Content.Items.ItemEntry.GetCodeFirstInstance(String systemName) +147
   Dynamicweb.Content.Items.ItemEntry.Save() +88
   Dynamicweb.Content.StructureChange.CopyPage(Int32& fromPageID, String& toLanguage, Int32& motherPage, Boolean& copyParagraphs, Boolean& copySubPages, Int32 copyID, Int32 sortVal, String newPageID, String copyTime) +1987
   Dynamicweb.Admin.Page_Copy.Page_Load(Object sender, EventArgs e) +720
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

 

 


Replies

 
Pavel Volgarev
Reply

Hi Morten,

 

It's a bug (TFS #11619 which is already fixed in the main development branch).

 

-- Pavel

 

 
Morten Bengtson
Reply

Hi Pavel,

 

The same error occurs when I try to use a template extender for items that implement IList properties. Bug 11617/11619 is making it impossible for us to continue our work on a project with a very tight deadline.

Do you know when this fix will be available? Do you know of any workaround?

 

/Morten

 

 
Nicolai Høeg Pedersen
Reply

Hi Morten

 

I've asked QA to make sure we can release these fixes as hotfixes. We need to merge first and make the release.

 

BR Nicolai

 
Brian Bolks
Reply

Bump on this old issue, we are having the same issue now. With code firstitem. using DW 9.10.11

Creating / Saving works fine, but when we copy the page or deleted the we get the error when values are checked. If we clear the checked items the page can be deleted and copy'ed.

 

 
Brian Bolks
Reply

We found the culprit

 DeserializeFrom in the ItemEntry class doenst take into account to get fields from base classes when u use itemtype inheretance. 

So what i did now to fix is override the DeserializeFrom as luckily its a virtual and updated it to also get iets baseItems.

 
Nicolai Pedersen
Reply

Hi Brian

Nice find and work around. We will look into moving this one into the source.

Thanks for digging into this and sharing the solution - much appreciated.

BR Nicolai

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hi,

The issue is now bugged by Bug 3690 created. Thanks.

BR, Oleg QA

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply

Hi Brian

Problem has been fixed in Dynamicweb 9.10.14+ versions. 
You can get this from the release section https://doc.dynamicweb.com/downloads/releases

Kind Regards
Dynamicweb Support
Kristian Kirkholt

 

You must be logged in to post in the forum