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

Try our conversational search powered by Generative AI!

ContentAreaItem does not throw error when changing read-only values

Fixed in

EPiServer.CMS.Core 10.5.0

(Or a related package)

Created

Jan 23, 2017

Updated

Mar 30, 2017

Area

CMS Core

State

Closed, Fixed and tested


Description

A read-only ContentArea contains a read-only collection of ContentAreaItem (ContentArea.Items). But the properties on the ContentAreaItem can be modified, causing corruption to the dictionary. Changing properties should throw exceptions to clearly indicate they are read-only.

For example, changing ContentAreaItem.RenderSettings from multiple threads could cause exceptions like "ArgumentException: An item with the same key has already been added" or "System.ArgumentNullException: Value cannot be null. Parameter name: key"
It could also corrupt the dictionary causing problems that can only be solved by restarting the application. In addition, such changes can cause more subtle errors, such as rendering sometimes shows incorrect values since multiple threads are using the same instance. It could also be that the editor is shown incorrect values when editing content areas.

This fix applies read-only semantics where it was missing to protect against this type of errors.

Workaround: ContentAreaItem originating from a read-only content should not be modified at runtime. To make changes to a stand-alone ContentAreaItem, create a new instance, copy the existing properties, then make changes (or use ContentAreaItem.CreateWritableClone, which this bugfix adds).