I recently upgraded a MOSS 2007 site to SharePoint Server 2010 which seemed to go relatively smoothly, however a short while after the upgrade a user reported they got an error when trying to set the theme on a new site.
When I checked this was indeed the case i got an object reference not set to an instance of an object error, see full error below. I spent some time looking into this and researching information online and I was able to establish the error was down to the fact that the theme gallery had not been created in the upgraded site.
I found some articles, see below, that seemed to deal with the same issue and while I found the information useful it didn’t supply instructions on how this could be achieved hence why I decided to document the steps I performed to correct this.
From looking at the articles above the options were to re-create the theme gallery or redo the upgrade. Realistically redoing the upgrade was not an option so this left me with trying to either move the theme gallery from another site collection or recreating it.
My first though was this was something I could do through SharePoint Designer so I opened a test SharePoint 2010 site and tried to export the themes list but quickly found this was not possible.
My next attempt was to try and copy from one SharePoint Designer instance to another. To do this I created a test site collection on the production environment and opened this in SharePoint Designer. With two SharePoint Designer windows open side by side I tried to copy the theme gallery from the test site and paste it into the upgraded site. This partially worked but it re-created it as a folder not a list so while I could browse to the URL it didn’t recognise it as a list.
Next I tried copying the theme gallery as a list template and re-create it using this. I navigated to the theme gallery on my test site collection and went to the settings but found there is no save list as a template option on this list. I got around this by getting the list ID of the theme gallery and then going to save another list and clicking save as a template. In the new screen I then replaced the list ID in the query string with the theme gallery list ID. This then allowed me to save the gallery as a template and I could see it in the list gallery. When I then went to create a new list I found the template I saved was not available. Thinking about it this made perfect sense as the default theme gallery list definition is mark as hidden so any new templates created using this type of list would also be hidden.
The solution that finally work was to create a new list through the UI but change the URL to supply the out of the box theme gallery list template ID. From research online I was able to identify that the theme gallery template ID was 123 so I went to the root of my site and created a list as normal but I then changed the URL removing the feature ID and changed the ListTemplate querystring parameter to 123. I entered the list name as theme and clicked ok. This created my list as expected but it was still in the wrong location. In order for the theme functionality to work the list had to be under the catalogs folder. To move the list I opened SharePoint Designer and simply dragged the list to where it should be. At this point I could now use the set theme functionality but there were no items so once again I opened my test site collection in SharePoint Designer and copied all the themes across to my upgrade site. When I then refreshed the choose theme page it worked and all the themes were available to choose from.
Being a developer normally I don’t use SharePoint Designer, however in this case I found it extremely useful to be able to move and manipulate objects in the SharePoint site.
Hopefully other people will find this useful, however please ensure if there is anything you are not sure of try it on a development environment first and always ensure you have a back up you can revert to before stating any work.
Full Error Details
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
Thread ID: 9
Thread account name: DomainOurAccount
Is impersonating: False
Stack trace: at Microsoft.SharePoint.ApplicationPages.ThemeWebForm.<>c__DisplayClass2.<LoadV4Page>b__0()
at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)