Try our conversational search powered by Generative AI!

PropertyList not working - can not be mapped to a MetaDataType

Vote:
 

I'm on EPiServer CMS 9.6.1 and have been following Per Magne Skuseth's blog post "Trying out PropertyList". I can see plenty of others commenting on that post who have gotten much further so it must be possible.. But for me when I have the property like this:

public virtual IList CustomerSkus { get; set; }

I keep getting the NotSupportedException with "The property data type IList can not be mapped to a MetaDataType".

And I've tried putting [BackingType(typeof(CustomerSkuListProperty))] and I then get NotSupportedException "The property data type Json can not be mapped to a MetaDataType".

I have definitely included the:

[PropertyDefinitionTypePlugIn]
public class CustomerSkuListProperty : PropertyListBase
{ }

And have copied the PropertyListBase exactly as in his post so cannot figure why I get those exceptions..

Oh and the CustomerSku class is pretty simple like this:

public CustomerSku
{
    public string AccountNumer { get; set; }
 
    public string Sku { get; set; }
}

Anything I might have missed?

#144180
Feb 09, 2016 0:06
Vote:
 

Did you add the EditorDescriptor to the property?

#144194
Feb 09, 2016 8:55
Vote:
 

You will need to supply a JsonConverter for CustomerSku to get this to work since this is CatalogContent I assume.  I would also suggest not trying to do this either as it was not inteded to store list of contentdata.  If you want a list of Content use the following instead, with allowed types.

[CLSCompliant(false)]
[AllowedTypes(typeof(CustomerSku))]
[Display(Order = 10)]
public virtual IList<ContentReference> Items { get; set; }

Sorry misread the post and was confused by MetaDataType.  Seems you may have another class called CustomerSku that is intefering. Can you try overrriding these methods in your PropertyList.  

public override PropertyData ParseToObject(string value)
        {
            var prop = new PropertyCustomerSkuList();
            prop.ParseToSelf(value);
            return prop;
        }

        
        protected override CustomerSku ParseItem(string value)
        {
            return Parse(value);
        }

        /// <summary>
        public override string ToString()
        {
            if (IsNull)
            {
                return String.Empty;
            }
            return string.Join(StringRepresentationSeparator.ToString(),
                List.Select(x => x.ToString));
            //this needs to handle representing the object as a string
        }
#144214
Edited, Feb 09, 2016 11:03
Vote:
 

@Daniel: Thanks, but yeah I did and it didn't help :-/

@Mark: Great, thanks - I'll try that out and report back!

#144216
Feb 09, 2016 11:14
Vote:
 

Hi Mark

I tried changing my CustomerSkuListProperty to be like this:

public class CustomerSkuListProperty : PropertyListBase<CustomerSku>
{
    public override PropertyData ParseToObject(string value)
    {
        var prop = new CustomerSkuListProperty();
        prop.ParseToSelf(value);
        return prop;
    }

    protected override CustomerSku ParseItem(string value)
    {
        return base.ParseItem(value);
    }

    public override string ToString()
    {
        if (IsNull)
        {
            return string.Empty;
        }
        return string.Join(StringRepresentationSeparator.ToString(),
            List.Select(x => x.ToString()));
        //this needs to handle representing the object as a string
    }
}

But still the same exception:

The type System.Collections.Generic.IList`1[[Navico.B2B.Buybook.Web.Models.Catalog.CustomerSku, Navico.B2B.Buybook.Web, Version=1.0.6.41827, Culture=neutral, PublicKeyToken=null]] can not be mapped to a MetaDataType

:-/

Matt

#144227
Edited, Feb 09, 2016 14:17
Vote:
 

Do you have two CustomerSkus because the error looks like it is a Catalog content type it is trying to use.  Are you sure it using your poco object.  Also what are you trying to achieve.  Maybe IList<ContentReference> is better

#144230
Feb 09, 2016 14:20
Vote:
 

Hi Mark

I only have one CustomerSku class in the solution and it's definitely a plain POCO - and only has string getter/setter properties (like in my first post).

Don't think ContentReferences are what I want since the intent is to have a simple list of sku strings for the variation content.

I'm just going to use a commerce MetaStringDictionary (MetaField) instead - I had seen the PropertyList and expected it to be a better way to go, but since I can't figure this out I'll skip using it for now.

Thanks for all your help and advice though!

Matt

#144253
Feb 09, 2016 23:37
Vote:
 

I think you need to add a BackingType of string since the catalog content provider does not know how to use the PropertyList

#144348
Feb 11, 2016 10:14
Vote:
 

Thanks Mark, yeah perhaps that's what I've missed here - If the content provider is different I guess that might be why. Appreciate your input!

#144383
Feb 11, 2016 21:54
Vote:
 

Hey Guys, 

I know this is an old post, but I got the same error when I try to use IList property into the commerce catalog (e.g. ProductNode).

So for the solution, I have added the BackingType attribute on the property and pass the xxxxProperty into typeof(xxxxProperty).

Step 1: Create a Model

public class ThreeColumnModel
{
  public virtual string Title { get; set; } 
  public virtual string Summary { get; set; }
}

Step 2: Register Model as property

[PropertyDefinitionTypePlugIn()]
public class ThreeColumnModelProperty : PropertyList<ThreeColumnModel>
{
}

Step 3: Add the BackingType attribute and used EditorDescriptor for registering the collection type model.

[BackingType(typeof(ThreeColumnModelProperty))]
EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<ThreeColumnModel>))]
public virtual IList<ThreeColumnModel> ThreeColumns{ get; set; }

Thanks,

#225725
Jul 24, 2020 15:14
Praful Jangid - Jul 25, 2020 1:13
Good job
* 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.