Try our conversational search powered by Generative AI!

PropertyListBase with page reference import throws exception


Hi guys,

We have a PropertyListBase 

    public class PagesListProperty : PropertyListBase<ApplicationPage>

and Application page as 

 public class ApplicationPage
        public PageReference Page { get; set; }

        public string Name { get; set; }


This property works fine and we get a nice interface in edit mode, where we can enter multiple items and each item has a page reference and a string.

We have exported this page and trying to import in a new env, but getting the following error Unable to cast object of type 'EPiServer.Core.UnresolvedContentReference' to type 'EPiServer.Core.PageReference'.] & the import fails.

All the pages that are selected within this property are part of the export package. 

Anyone know how can I make this work?


Edited, Sep 15, 2021 9:55

I think ApplicationPage is missing inherited Episerver type, tyically ContentData

Sep 17, 2021 6:18

I've used ContentReferences on PropertyLists and I've been able to import and export successfully between environments.  I have noted that where Url properties are used, these have needed decorating with the [JsonConverter(typeof(UrlConverter))] attribute if you want to use them in a property list or if you want to use it on a content type that will be imported and exported between systems.  I believe this is because the import / export mechanism uses json files.

This may actually be failing because there is a missing json convertor for PageReference, you could try writing your own simple convertor for this?

Oct 01, 2021 15:39

Absolutely Stotty. We can add a PageReference converter like the one for UrlConverter. 

    public class PageReferenceConverter : JsonConverter
        public override bool CanConvert(Type objectType) => typeof(PageReference).IsAssignableFrom(objectType);

        public override object ReadJson(
            JsonReader reader,
            Type objectType,
            object existingValue,
            JsonSerializer serializer)
            return reader.Value != null ? (object)new PageReference(reader.Value.ToString()) : (object)null;

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
            if (!(value is PageReference pageReference) || PageReference.IsNullOrEmpty(pageReference))

~ Sujit

Edited, Oct 07, 2021 16:45

When PropertyList is saved/loaded from db it does not use the converters registered in IOC container since those are used when sending/getting data from the client and that format is not nessecarily the same format as we want to persist in database. So to get you converter to be used when loading/persisting data from database you need to decorate your PageReference property on your model, like:

public PageReference Page { get; set; }
Oct 15, 2021 7:21
* 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.