Try our conversational search powered by Generative AI!

Trying to use the ContentReferenceList property but getting exception

Vote:
 

I'm trying to use a very simple ContentReferenceList like this:

public virtual IList MediaFiles { get; set; }

But I am getting the exception:

System.NotSupportedException: The type System.Collections.Generic.IList`1[[EPiServer.Core.ContentReference, EPiServer, Version=11.9.3.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7]] can not be mapped to a MetaDataType

Seems like this should be simple - so hopefully I've missed something obvious?

[I'm using Episerver CMS v11.9.3]

#196043
Aug 17, 2018 4:42
Vote:
 

Well, that was a pretty silly post.. Forgot that this is on a Product so is the Commerce content provider which won't have compatibility for things like PropertyList! Oops, I'll leave this here for future me in case I do the same thing again :)

#196044
Aug 17, 2018 5:38
Vote:
 

If you add the attribute

        [BackingType(typeof(PropertyContentReferenceList))]

To your property it will work. All the ILists work as long as you set the correct backing types so that commerce knows the correct meta data field to map to

#196051
Aug 17, 2018 9:52
Vote:
 

Commerce contents have full support for IList<T> - well, except for inside blocks (which is coming soon). However you need to specify a BackingType as Scott said 

#196053
Aug 17, 2018 10:13
Vote:
 

Oh, in that case I’ll give that a try. I often run into weird limitations with Commerce content so just assumed this was another. Thanks Scott and Quan for the replies!

#196063
Aug 17, 2018 12:29
Vote:
 

Just follow up message to say Scott and Quan were right :) 

My property as follows works well:

[BackingType(typeof(PropertyContentReferenceList))]
[Display(
Name = "Media files",
GroupName = SystemTabNames.Content,
Order = 130)]
[AllowedTypes(typeof(MediaData))]
public virtual IList<ContentReference> MediaFiles { get; set; }

Thanks again.

#196098
Aug 18, 2018 10:56
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.