Try our conversational search powered by Generative AI!

Giang Nguyen
Nov 7, 2019
  3602
(1 votes)

Problematic serialization of EPiServer.Url class in CMS 11

What happened?

Recently, I found out some problem with EPiServer.Url objects, mostly because of its serialization.

Let's start with a demonstration like this:

// The page model
[ContentType GUID="..."]
public class MyPage : PageData
{
    [EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<MyType>))]
    public virtual IList<MyType> MyTypeList { get; set; }
}

// The MyType class
[Serializable]
public class MyType
{
    public string WorksNormal { get; set; }
    public EPiServer.Url WontWork { get; set; }
}

// The definition so it won't cause problem with the editor
[PropertyDefinitionTypePlugIn]
public class DecisionItemListProperty : PropertyList<MyType>
{
}

The innocent-look code above seems to be fine and quite simple to most developer. However, there are 2 dreadful error happen in CMS 11 (while it's totally fine with version 10)!

Firstly, the CMS editor's behavior becomes strange when I tried to add MyType objects to the list. Everything is okay in the editor from the popup, workflow, UI. Surprisingly, after saving the page, regardless it's published or saved as draft, every data of MyType.WontWork is gone while everything is saved as expected. No warning or error or stack trace in log file!

Secondly, Find failed indexing the page, every traces point to MyType.WontWork object. I doubt that Newtonsoft.Json seems unable to serialize the Url class (it works okay if [JsonIgnore] is present).

How come?

What I found regards to this is here https://world.episerver.com/features/episerver-features---november-2017/, in PropertyList<T> improvements (Beta removal) section. However, thing there point out directly if the Url class is affected or not, no warn or suggestion for code changes.

I am also awaiting a comment here to help me figure out the root cause of this.

How to fix?

Easy peasy. Just add some annotation to the Url property, so it will look like this:

[JsonProperty]
[JsonConverter(typeof(UrlConverter))]
public EPiServer.Url WontWork { get; set; }

Just that! It would be fine.

Nov 07, 2019

Comments

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog