Anders G. Nordby

Lead Consultant at Itera

Monthly Archives: February 2014

EPiServer 7.5: Problem with Updating PageTypes

For the site I’m working on, we’re creating a calculator for helping visitors select the right products. This kind of thing is very popular at the moment – I’m starting to wonder if there are any frameworks or domain specific languages for creating this kind of calculators? Well, anyway, we’re doing this the old-style way… So I have a pagetype called RoofCalculatorPage, because the site is about construction work. The calculator consists of several steps, and to make it easy for the editors (and us developers), I’ve created a blocktype for each step. As the blocktype is only used for grouping properties, I’ve created it like this (note the AvailableInEditMode = false to make sure it’s not possible for editors to create instances of this block):

    [ContentType(
        DisplayName = "RoofCalculatorStep1Block", 
        GUID = "8274e516-95b5-4e75-b80c-26d90f961297", 
        Description = "",
        AvailableInEditMode = false
        )]
    public class RoofCalculatorStep1Block : BlockData
    {
        public virtual string Title { get; set; }
    }

So I have many of these, and I then litter my RoofCalculatorPage with them. Since this is a copy paste job, and I’m working quickly on this, I end up making a common type of copy-paste-error:

    [ContentType(
        DisplayName = "RoofCalculator", 
        GUID = "19777f46-2d73-4977-8b51-8dbe83058ad0", 
        Description = "The roof calculator page"
        )]
    public class RoofCalculatorPage : SitePageData
    {
        [Editable(true)]
        [Display(
            Name = "Step 1",
            GroupName = SystemTabNames.Content
            )]
        public virtual RoofCalculatorStep1Block Step1 { get; set; }

        [Editable(true)]
        [Display(
            Name = "Step 2",
            GroupName = SystemTabNames.Content
            )]
        public virtual RoofCalculatorStep1Block Step2 { get; set; }

        [Editable(true)]
        [Display(
            Name = "Step 3",
            GroupName = SystemTabNames.Content
            )]
        public virtual RoofCalculatorStep1Block Step3 { get; set; }

For those who don’t spot this immediately, notice that I’ve set all my steps to be of the type RoofCalculatorStep1Block. Now, this results in the following situation:
RoofCalculator-error-all-same

I spot this fairly quickly – oops, a glitch there – fix it, and rebuild. Now everything is fine, right? Wrong! The situation is still the same, the admin GUI looking exactly as before. A bit perplexed, I blink, and go back to my Visual Studio window. Yes, I did really build, the text “Build succeeded” is still visible at the bottom of the screen. I go to the browser, and hit Ctrl+F5. Same result. I rebuild, just for the heck of it, then refresh my browser again. Still the same.

For a while I fiddle around in the admin GUI, thinking there surely must be some way of telling EPiServer to refresh the properties, since what’s in the DB is obviously inconsistent with what’s in the code. Nope! I find no way of doing this from the GUI. The only way I could find to fix the situation, was to comment out (remove) the properties from code, rebuild, refresh browser – which of course removed all the properties – and then comment the properties back in again, rebuilding and refreshing once more.

This problem is actually quite serious. Why? Because, suppose another of the developers on my team decided to change a property from one type to another… Then I’ll not be able to see the update – and I might not even know about the fact that he’s just updated this particular type.

Advertisements