In this blog post I will take a look at some of the do’s and don’ts of using PropertyList. PropertyList has been around for a while and some
niceblogposts have been written about the subject. If you create a new PropertyDefinition based on PropertyList you might notice that PropertyList is still a pre-release API (Assembly: EPiServer, Version=10.4.2.0):
NOTE: This is a pre-release API that is UNSTABLE and might not satisfy the compatibility requirements as denoted by its associated normal version.
But we didn’t seem to have too much problems with PropertyList, so what could be the reason for it to be a pre-release API still?
To demonstrate the dangers of using a pre-release API I've used the example code from the first blogpost mentioned above.
Adding PropertyList property to a page
First we have the PropertyDefinitionType and the PropertyListBase (notice the Typo):
Then we create a simple model that we want to store in a list:
And lastly string it all up together and add a property to a pagetype:
Doing so will allow you to use a list of MyCustomData to our PropertyListProblemsPage (uhoh, sounds like trouble already).
Fixing a typo
I just noticed that my PropertyDefinitionTypePlugIn has a type, namely it is called TypoListProperty instead of MyCustomDataListProperty.
So let’s change the class name to MyCustomDataListProperty and see what happens next.
We can’t seem to access the site OR the CMS anymore! This error only occurs if there’s data in the current draft of the page. Let’s see what kind of useful information the error log has for us:
Not that useful now is it? The same behaviour occurs if you were to change the namespace, for example during refactoring.
The error shown above is during initialization, however it seems that all front facing pages seem to break before your app recycles.
After the app recycle however you will not be able to access the CMS anymore.
So what if we change logging to log all messages? We get a little bit closer because of the warning but still way too obscure:
What if this happens in production?
Obviously this error should’ve already occured on your test or staging environment. But what if, in worst case, you have to fix this on a production environment.
If this error occurs in production you don’t have a lot of options. The CMS isn’t available so you’ll have to do some digging in the database.
First you’ll have to find you property definition in the [tblPropertyDefinition] table. Use the pkID to find both the data in the [tblContentProperty] and the [tblWorkContentProperty] table.
If you delete the data from those two tables you’ll be able to start your site again. Make sure to save the data if you want to keep it. After deleting the data, go to the admin mode, find the problematic property and switch it from Type “TypoListProperty” to “MyCustomDataListProperty”.
What can we learn from this?
In general it is advised to not use pre-release APIs at all. However if you’re willing to take the gamble, be prepared to run into problems like I’ve described in this post.
I’ve seen this error before but didn’t give it much notice, I always have a working database backup ready during development which increases the risk of having a mistake like this occuring on test.
How to change the namespace or rename TypoListProperty?
In my next blogpost I’ll show you how to move data in case you want to rename or refactor your ListProperty. I’ll also take a look at implementing PropertyList in a different, safer, way.
tl;dr?
Trying to change the (underlying) data of a PropertyList could prevent episerver from starting. See the next post for solutions