November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
The error is happening in EPiServer.Cms.Shell.UI.ObjectEditing.InternalMetadata.LinkModel.ToServerModel(object clientModel). If there isn't a LinkItem, clientModel is null, and therefore the line that reads if (linkModel.Attributes != null) will throw a System.NullReferenceException because linkModel is null. There needs to be a null-check after LinkModel linkModel = (LinkModel) clientModel;
Code in case the image doesn't work:
public virtual object ToServerModel(object clientModel)
{
LinkModel linkModel = (LinkModel) clientModel;
LinkItem serverModel = new LinkItem();
if (linkModel.Attributes != null) // <!!-- This is where it throws the System.NullReferenceException
{
foreach (KeyValuePair<string, string> attribute in linkModel.Attributes)
serverModel.Attributes.Add(attribute.Key, attribute.Value);
}
serverModel.Text = linkModel.Text;
serverModel.Title = linkModel.Title;
LinkItem linkItem = serverModel;
...
We have a block as a property for the page hero. Inside that HeroBlock, we have a LinkItem for a CTA button. If we don't have any LinkItems (call-to-actions), we can't save updates to the other properties like Title and Description when using on-page editing. The all-properties view works; however, we're prioritizing the on-page editing experience.
The error received is exactly "Could not save property, and it has been reverted. Please try again. Object reference not set to an instance of an object". When I check the console, there's an error that has the following stack trace and headers:
I have identified the problem as an attempt to deserialize a null value from the LinkItem object. Here is the Ajax payload being sent:
If a LinkItem is added to the CallToAction property everything works. Here is an Ajax payload with a LinkItem in the CallToAction property that allows me to update the Title or Description:
Finally, here is how the block is set up, in case that sparks an idea.
To get it to work, I'm trying to find where it gets deserialized to add a null check, but I have no idea where that could be. I've also seen this same issue in other unsolved forum threads going back to 2015.
https://world.optimizely.com/forum/developer-forum/CMS/Thread-Container/2017/10/json-serialization-error-when-creating-a-link-item/
https://world.optimizely.com/forum/developer-forum/CMS/Thread-Container/2015/11/unable-to-publish-linkitemcollection-properties/