Stefan Forsberg
Apr 17, 2010
  12643
(2 votes)

Using PageTypeBuilder with Composer

The problem

A colleague of mine had trouble using PageTypeBuilder on a project that was also using composer. Since going back to the dark ages without PTB seemed like some mild fun I decided to look into the issue.

 

Finding the error

To reproduce this bug I installed a site with CMS 5 R2 SP2 and Composer 3.2.6 and created a test page of type Composer Wide Page. I then added the PageTypeBuilder dlls to the project and when you do a Composer – edit on page (from the right click menu) on the created test page you get the following exception:

System.NullReferenceException: Object reference not set to an instance of an object.

Don’t you just love that exception?

The stack trace looks like this (I’ve removed the uninteresting parts):

   1: PageTypeBuilder.PageTypeResolver.ConvertToTyped(PageData page) in C:\EPiServer\Sites\_filesForComposerLab\PageTypeBuilder\PageTypeResolver.cs:65
   2: PageTypeBuilder.Initializer.DataFactory_LoadedPage(Object sender, PageEventArgs e) in C:\EPiServer\Sites\_filesForComposerLab\PageTypeBuilder\Initializer.cs:40
   3: EPiServer.PageEventHandler.Invoke(Object sender, PageEventArgs e) +0
   4: EPiServer.Core.PageStoreBase.RaisePageEvent(Object key, PageEventArgs eventArgs) +76
   5: EPiServer.DataFactory.GetPage(PageReference pageLink, ILanguageSelector selector) +341
   6: Dropit.Extension.UI.Edit.Controls.LanguageBranchControl.LoadLanguageBranch(PageReference pageLink) +379

 

We did some quick googling and found this blog post from Tomas Unestad at DropIt but that didn’t seem to be the problem we were getting here. We also found this forum post that seemed to be getting exactly the same error as we were experiencing but it didn’t have any replies.

So I fired up reflector and poked around the LanguageBranchControl to see what was going on and what was triggering PTB. It didn’t take long to found these lines

   1: PageData page = DataFactory.Instance.GetPage(pageLink, new LanguageSelector(branch.LanguageID));
   2: if (page != null)
   3: {
   4:     str = PageDataManager.BuildExtensionPageLink(page, ExtensionGeneric.ViewMode.ExtensionEditOnPageMode);
   5: }

GetPage will invoke PTB code because it hooks up to the event of a page being loaded (to be able to cast the page to the typed version). I noticed here that after the call to GetPage a check is performed to make sure that the returned page was not null. And PTB is throwing a NullReferenceException. That can’t be a coincidence.

 

“Fixing” the error

To be able to look at what’s happening I downloaded the source code to PTB and added it to my solution and instructed my EPi-project to work with that instead of the precompiled dll. I did a simple addition to the method that handles the event of a page being loaded from DataFactory.

   1: static void DataFactory_LoadedPage(object sender, PageEventArgs e)
   2: {
   3:     if (e.Page == null)
   4:     {
   5:         return;
   6:     }
   7:     
   8:     e.Page = PageTypeResolver.Instance.ConvertToTyped(e.Page);
   9: }

 

With the added lines 3-5 I also added a breakpoint there and tried the edit on page again. The breakpoint indeed was hit and I got the following info from the PageEventArgs:

ComposerPTBNullReference

PageLink 29 is my created test page (of type Composer Wide Type). Why this is sent here with a null Page I have no idea. The good news is that the application with the null check in place no longer throws an exception and works as expected.

 

So, you know… what about actually using PTB with composer functions?

Ehm yea, about that. I started looking into that but it turned out to be slightly more complex than I first had thought (at least with my non existing knowledge of Composer). Not impossible but a bit too much work for a casual Saturday post.

Maybe in a future post.

xoxo

Apr 17, 2010

Comments

Sep 21, 2010 10:33 AM

Good post Stefan!

I'll add that null check to the next release of PTB.
/ Joel Abrahamsson

Sep 21, 2010 10:33 AM

Great post.

Just let me know if you want to sit down for a "joint venture" and actually make it work togehther.

The beer is on us :-)
/ Fredrik Karlsson

Sep 21, 2010 10:33 AM

Grymt!!!
/ tor

Mari Jørgensen
Mari Jørgensen Sep 21, 2010 10:33 AM

Any updates on this one?

I have created functions with PTB using the following approach:
http://dungle30.wordpress.com/2010/06/24/create-composer-page-type-using-pagetypebuilder/

The functions get registered in admin mode, but are not available in the toolbox (and yes, I've checked access rights). If I try to export and import the functions, they show up in the toolbox.

Stefan Forsberg
Stefan Forsberg Sep 21, 2010 10:33 AM

Hello Mari,
unfortunetly I haven't done anything more in regards to PTB+composer or tried Dung Les approach so I can't be of any help.

Mari Jørgensen
Mari Jørgensen Sep 21, 2010 10:33 AM

I finally got it up and running - I'll put up a blog post about it shortly.

Stefan Forsberg
Stefan Forsberg Sep 21, 2010 10:33 AM

Ah great, I think that will make a lot of my colleagues (and other people using composer) very happy!

Please login to comment.
Latest blogs
How I Fixed DLL Conflicts During EPiServer CMS Upgrade to .NET Framework 4.8.1

We had a CMS solution of EPiServer 11.26.0, which was built on .NET Framework 4.7.1. We needed to update the target framework from .NET Framework...

calimat | Dec 12, 2024

Custom form element view in Optimizely CMS 12

Do you want full control over the form element markup? Create your own views!

Tomas Hensrud Gulla | Dec 11, 2024 | Syndicated blog

How to Elevate Your Experimentation - Opticon workshop experience

As a non-expert in the field of experimentation, I’d like to share my feedback on the recent Opticon San Antonio workshop session titled "How to...

David Ortiz | Dec 11, 2024

Persisting a Strawberry Shake GraphQL Client for Optimizely's Content Graph

A recent CMS project used Strawberry Shake to generate an up-to-date C# GraphQL client at each build. But what happens to the build if the GraphQL...

Nicholas Sideras | Dec 11, 2024 | Syndicated blog

Opti ID with Secure Cookies And Third Party AddOns

Opti ID has revolutionised access to the Optimizely One suite and is now the preferred authentication method on all PAAS CMS websites that I build....

Mark Stott | Dec 9, 2024

AsyncHelper can be considered harmful

.NET developers have been in the transition to move from synchronous APIs to asynchronous API. That was boosted a lot by await/async keyword of C#...

Quan Mai | Dec 4, 2024 | Syndicated blog