Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

change a ContentArea into a ContentReference

Vote:
 

I've been asked to change a property from a ContentArea into a ContentReference as we no longer need a list but only a sigle item. When I make the change to the code base, and try editting the changed property in the CMS, I get an error message telling me the site is offline when I try to publish (so I cant save or publish the page or anything), and inspecting the logs shows that it is throwing a cast exception:

System.Reflection.TargetInvocationException: Property accessor 'BannerOverride' on object 'Castle.Proxies.HomePageProxy' threw the following exception:'Unable to cast object of type 'EPiServer.Core.ContentArea' to type 'EPiServer.Core.ContentReference'.' ---> System.InvalidCastException: Unable to cast object of type 'EPiServer.Core.ContentArea' to type 'EPiServer.Core.ContentReference'.
   at Castle.Proxies.HomePageProxy.get_BannerOverride()
   --- End of inner exception stack trace ---
   at System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component)
   at EPiServer.Validation.DataAnnotationsValidator`1.ValidateInstance(Object instance, List`1 validationResult, ValidationContext validationContext)
   at EPiServer.Validation.DataAnnotationsValidator`1.Validate(T instance)

I can fix this issue by removing the data from the ContentArea before deploying the new property type, but as that could be troublsesome on a large site (this property just so happens to be on EVERY page on the site), what is the recommended way of making this sort of change?

#199207
Nov 20, 2018 11:41
Vote:
 

So apparently I missed an extra Range Validator on the property, which was causing an extra error, after that I got this new error message :

2018-11-20 11:17:27,172 [75] ERROR EPiServer.DataAbstraction.RuntimeModel.Internal.ContentTypeModelRegister: Detected change of type on property BannerOverride on HomePage. Converting existing content of type EPiServer.SpecializedProperties.PropertyContentArea to new backing type EPiServer.Core.PropertyContentReference is not possible without loss of data. No change is commited.

but this error message only appear a couple of times, but then went back to the orriginal message. Just adding this error message for completeness.

#199209
Nov 20, 2018 12:24
Vote:
 

IMHO it would be easiest to remove the old property and create  a new one. Or you could just add a validator on the ContentArea that would limit the amount of items that can be added to just 1?

#199212
Nov 20, 2018 13:01
Vote:
 

Well the "extra Range Validator" I mentioned was doing excatly that, limiting the ContentArea to a single item, but I think the decision was that the "editor experience" is better with just a ContentReference

I think you may be correct about creating a new property, but obviously removing the old property is not an option (for this thought experiment at least) because perhaps the property already has a value in it? In this instance we dont want to interrupt UAT with this change, so we want it as a seamless experience for editors, without having to tell them they have to re-edit (potentially) hundreds of pages because of a change we've made.

#199213
Edited, Nov 20, 2018 13:31
Vote:
 

Ah, well... In that case you coud hide the ContentArea in edit mode I guess, and make the view display the ContentArea except when the ContentReference has a value?

#199214
Nov 20, 2018 14:06
Vote:
 

I agree with Jeroen, do like this:

1: Create a new property that is a content reference

2: Update the Content Area property to not be visable in the edit mode

3: If you use a view model have the logic to pick the value from the content reference if there is any otherwise pick the content area

4: Create a scheduled task that updates all pages that have a value in content area to be a value for the content ref

Next release

Remove the content area property

Delete the content area property from admin (since it will remain there since there would still be content with value in it)

Remove the extra logic for selecting the correct value.

True this is a lot of extra work but for complex stuff like this there is pretty much no other way and you do not want to have old not used properties in your solution

#199215
Nov 20, 2018 14:46
Vote:
 

thanks @Henrik and @Jeroen, from your replies I can tell I'm not missing an obvious solution to this one.

As we are only in UAT at the minute, and the property is not currently in widespread use, so these are the steps I'll be taking...

  1. manually recording what is in the field on any pages
  2. clearing any instances where it's set,
  3. doing a code deploy which changes the property type
  4. re-entering the previously removed values. 
#199216
Nov 20, 2018 15:13
Vote:
 

Sounds great Noel

#199220
Nov 20, 2018 17:33
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.