Ruslan Minasian
Nov 4, 2010
  3695
(0 votes)

Custom Property Type and SaveData Method

In out project we use PropertyPageReferenceCollection to store references to local pages. It has PageReferenceCollection under the hood and calls its Parse and ToString methods to load and save the data. Evetything was fine until we decided to make some property (let’s call it Links) of this type required. The application started to crash while loading the page with empty Links property.

I’ve spend a lot of time looking how to prevent LoadData from crash while the error was in SaveData method. When LocalPageProvider loads a page it goes through all the properties from DB calls PropertyData.LoadData method for each property which value is not DBNull.Value. Since our SaveData implementation used PageReferenceCollection.ToString it returned string.Empty for empty collection and that value was stored in the DB. Then, after we set Links property as required, LoadData started to crash since string.Empty caused PropertyData.Clear to be called for required property.

Moral: always implement SaveData property so it returns null if PropertyData.IsNull is true.

Nov 04, 2010

Comments

Please login to comment.
Latest blogs
Recraft's image generation with AI-Assistant for Optimizely

Recraft V3 model is outperforming all other models in the image generation space and we are happy to share: Recraft's new model is now available fo...

Luc Gosso (MVP) | Nov 8, 2024 | Syndicated blog

ExcludeDeleted(): Prevent Trashed Content from Appearing in Search Results

Introduction In Optimizely CMS, content that is moved to the trash can still appear in search results if it’s not explicitly excluded using the...

Ashish Rasal | Nov 7, 2024

CMS + CMP + Graph integration

We have just released a new package https://nuget.optimizely.com/package/?id=EPiServer.Cms.WelcomeIntegration.Graph which changes the way CMS fetch...

Bartosz Sekula | Nov 5, 2024

Block type selection doesn't work

Imagine you're trying to create a new block in a specific content area. You click the "Create" link, expecting to see a CMS modal with a list of...

Damian Smutek | Nov 4, 2024 | Syndicated blog