Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Object reference error when saving content

Found in

EPiServer.CMS.Core 11.20.2

Fixed in

EPiServer.CMS.Core 11.20.4

(Or a related package)

Created

Jan 08, 2021

Updated

Feb 10, 2021

Area

CMS Core

State

Closed, Fixed and tested


Description

Steps to reproduce:

  1. On an Alloy site, create a property in an EditorialBlock, as below:
[Display(
 GroupName = SystemTabNames.Content,
 Order = 320)]
 [MaxLength(10)]
 public virtual string MyString { get; set; }
  1. In admin view, add a property named EditBlock1 with type EditorialBlock to News Page:
  2. In edit view, create a new page with type News Page, edit the Main Body property of EditorialBlock (for example, set the Main Body text to 'Test') then publish the page.
  3. Set the MyString property of the EditorialBlock as [Required].
  4. Dynamically update content of the page as following code:
         var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>();
         var content = contentRepository.Get<NewsPage>(new ContentReference(113)); // assume that the newly created page has ID 113
         var c = content.CreateWritableClone();
         c.Property["EditBlock1"].Clear();
         contentRepository.Save(c); 

Expected result:

Content is updated successfully.

Actual result:

Exception `Object reference not set to an instance of an object` is thrown.