Try our conversational search powered by Generative AI!

Lee Crowe
Apr 23, 2012
(4 votes)

PageTypeBuilder and EPiServer CMS 6 R2 Synching Issues – Important


There have been a couple of issues that have been logged on codeplex to do with long start up times and default values not being set on page definition properties, the links to the issues are below:

- After upgrading to PTB 2.0, starting site takes a really long time

- Default value is not set

Basically there was a change in CMS 6 R2 which changed how sort orders are handled.  When PageTypeBuilder is synching it will compare whether the page definition is different to the one stored in the database and if so it will update it.

In CMS 6 R2 a new method is now called named EnsureUniqueFieldOrder within the Save method of the PageDefinition.

At a high level this method does the following:

  1. Checks whether the sort order for the current page definition matches the sort order of any other page definitions for the page type and if it does it will set a new value for it.
  2. If a sort order has not been defined and there are existing page definitions it will get the highest sort order and add 1 to it.

This then has a potentially huge knock on effect because the next time the application starts PageTypeBuilder will go off and work it’s magic, but because the EnsureUniqueFieldOrder method has changed some of the sort orders, PageTypeBuilder will determine that the page definitions are different and update the definitions again Sad smile.

So to put simply this is not a bug in PageTypeBuilder or EPiServer it’s just a unfortunate side effect of not defining your Sort Order's in your page types or specifying duplicates.  Over time we often have many common base classes that page types will inherit from and can often be a case for many duplicates.

Introducing PageTypeBuilder.SortOrderChecker

Some of you may be aware that I spend a lot of time commuting to and from London town and that I like to fill this time with knocking together useful modules and applications.

So last week to fill this time I decided to knock together a little console application which will scan a bin folder and tell you which page types have duplicate and undefined properties.

It can also fix all of the page type files for you (assuming you are programming in C#) and apply new sort orders for various property definitions including property groups.  The fixing code will also fix sorting on page type and property group base classes too to ensure there are no duplicates.

Using PageTypeBuilder.SortOrderChecker

Firstly you will need to Download the executable and it’s config file from here and dump it in a folder on your machine. Then you need to follow the steps below:

1. Re-build your application to make sure all of your assemblies are up to date.
2. Backup any relevant EPiServer databases and source files Confused smile

3. Then you can execute the tool with the following arguments to determine which properties have duplicate or undefined sort orders.

c:\Tools\PageTypeBuilder.SortOrderChecker.exe -t:0 -b:c:\episerver\sites\pagetypebuildertest\bin

You will be shown a window like the following:

4. You can then attempt to fix your page types by running the following command, please note you may need to close visual studio first just in case there are any file locks.

c:\Tools\PageTypeBuilder.SortOrderChecker.exe -t:2 -b:c:\episerver\sites\pagetypebuildertest\bin -p:c:\episerver\sites\pagetypebuildertest

You will be shown a window like the following:

5. Now that your files have been fixed, you will need to rebuild the solution.  It may be possible that some classes/properties will not be updated, but this would probably be because of bad coding style, not by me of course Winking smile

Now we have rebuilt we can run the tool again to check for duplicates and unassigned sort orders.

c:\Tools\PageTypeBuilder.SortOrderChecker.exe -t:0 -b:c:\episerver\sites\pagetypebuildertest\bin

This time you will hopefully be told that all duplicates and unassigned sort orders are no more Thumbs up.

One thing to be aware of is that as EPiServer has done it’s own thing for duplicate and undefined sort orders, it may still be likely that are some duplicates even though there are none in code.

To get round this you can run the tool again with the following commands.

c:\Tools\PageTypeBuilder.SortOrderChecker.exe -t:3 -b:c:\episerver\sites\pagetypebuildertest\bin -o:c:\temp\ResetSortOrders.sql 

This will create a .sql file with the necessary SQL to reset all PageTypeBuilder Property Definition sort orders to 0, so you will need to execute the SQL against your database.

7. Now that sort orders have been reset you can run your application. 

If you have a large number of page types and page definitions this initial update may take a bit longer than expected, but once this initial update is complete all future deployments/application restarts should be much quicker Smile.

Checking Sort Orders on post build event

You can hook the sort order checking executable into your application build by calling it on a post build event, it's not particularly elegant but will fail the build if there are duplicate or undefined sort orders and will output duplications and undefined properties on page types to the output window.

Command for post build:

c:\Tools\PageTypeBuilder.SortOrderChecker.exe -t:1 -b:$(TargetDir)


Although I have done testing around this there could be possible side effects.  I take no responsibility for any adverse affects.  So basically use at your own risk and backup your database and source code first.


Please feel free to email or twitter me with any feedback @croweman

Apr 23, 2012


tompipe Apr 23, 2012 12:25 PM

Nice, very nice.

Apr 23, 2012 12:46 PM

If anyone is brave enough it would be interesting to find the maximum number of duplicate/undefined sort orders and hear about the performance increase differences :)

Lars Bodahl
Lars Bodahl Apr 23, 2012 04:13 PM

Nice :) Our project implemented a similar, but more basic console app two weeks ago. Lots of pagetypes and several properties with duplicate sortorder. We reduced startuptime from 18 minutes to 2 minutes :-D

Filips Gajevskis
Filips Gajevskis Apr 23, 2012 07:38 PM

Great tool! Reduced start up time at about 30%.

P.S. Also mentioned a little bug, that if pagetype property is empty like PageType (), it adds SortOrder with comma like PageType (SortOrder = 32, ), that leads to an error when compiling.


Apr 24, 2012 10:21 AM

Cool, I did consider the empty PageType attribute but I didn't think anyone would actually do that ;)

James Hurst
James Hurst Apr 25, 2012 10:54 AM

Great one. Managed to knock off about 40% off the start up time.
Now just got to get the other devs not to go and mess up my lovely ordering.....

Apr 25, 2012 11:01 AM

Hi James

If you add the post build event mentioned in the article to the build the over dev's will not be able to break it :)


Apr 27, 2012 11:17 AM

To verify that there are no more duplicates in the database you can you the following query, it should return no results. The where condition ignores undefined sort orders.

SELECT [fkPageTypeID], [FieldOrder]
FROM [tblPageDefinition]
WHERE [FieldOrder] > 0
GROUP BY [fkPagetypeID], [FieldOrder]
HAVING COUNT([FieldOrder]) > 1

Anders Murel
Anders Murel May 6, 2012 09:03 PM

God bless you!!

tompipe May 15, 2012 05:21 PM

Thanks for re-tweeting this today Lee, I'd totally forgotten about it, and have been suffering with slow startups on the project I'm working on this week.

I'd used the PTB classes to discover properties which were using the default sort order, or were out of sync with the DB. There were loads, so I opted not to manually update them all at that point......thankfully.

I've just run your console app, and there were:

131 properties have duplicate sort orders
1408 properties have undefined sort orders
1539 properties have duplicate or undefined sort orders
page load took 144.109 seconds.

Running the fix reduced page load to 29.544 seconds and saved me from manually updating all the code!

I owe you a beer :)

Aug 14, 2013 01:32 PM

Thanks a lot croweman this helped me...

Cheers :-)

Please login to comment.
Latest blogs
Optimizely Web... 6 Game Changing Features in 2024

If you are interested in learning about what's new within Optimizely Web, you are in the right place. Carry on reading to learn about the 6 greates...

Jon Jones | Mar 3, 2024 | Syndicated blog

Headless forms reloaded (beta)

Forms is used on the vast majority of CMS installations. But using Forms in a headless setup is a bit of pain since the rendering pipeline is based...

MartinOttosen | Mar 1, 2024

Uploading blobs to Optimizely DXP via PowerShell

We had a client moving from an On-Prem v11 Optimizely instance to DXP v12 and we had a lot of blobs (over 40 GB) needing uploading to DXP as a part...

Nick Hamlin | Mar 1, 2024 | Syndicated blog

DbLocalizationProvider v8.0 Released

I’m pleased to announce that Localization Provider v8.0 is finally out.

valdis | Feb 28, 2024 | Syndicated blog