forge

Don’t Deactivate that Site Template Solution

It’s open season for hunting down SharePoint 2010 bugs and I’ve found a particularly ugly one. I created a site from a site template, and when I went in to the solution gallery and deactivated the solution (after the site was created) the solution gallery began throwing an exception:

[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.SharePoint.WebPartPages.ListViewWebPart.PrepareContentTypeFilter(SPList list, Hashtable[] excludedTransformers) +176
Microsoft.SharePoint.WebPartPages.ListViewWebPart.GenerateDocConvScriptBlock(SPWeb web, SPList list) +482
Microsoft.SharePoint.WebPartPages.ListViewWebPart.OnPreRender(EventArgs e) +1957
Microsoft.SharePoint.WebPartPages.WebPartMobileAdapter.OnPreRender(EventArgs e) +78
System.Web.UI.Control.PreRenderRecursiveInternal() +11025422
System.Web.UI.Control.PreRenderRecursiveInternal() +223
System.Web.UI.Control.PreRenderRecursiveInternal() +223
System.Web.UI.Control.PreRenderRecursiveInternal() +223
System.Web.UI.Control.PreRenderRecursiveInternal() +223
System.Web.UI.Control.PreRenderRecursiveInternal() +223
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3393

The specific steps are really simple…

Help Your SharePoint User
  1. Create a blank site.
  2. Save site as a template.
  3. Create a new site collection but don’t establish a template
  4. Upload the template created in step #2 to the solution gallery and activate
  5. Create the site with the template.
  6. Go to the solution Gallery and deactivate the solution.

If you want or need to get back to a partially useful state you can do the following steps in the SharePoint Management Shell..

$site = get-spsite http://localhost/sites/mysitehere
$solutions = $site.Solutions
$solutions.Add(1)

The moral to this story is don’t deactivate the site template that you created a site from (at least not at the moment). In SharePoint 2007 you could remove a site template’s STP file once the site was created because the STP file was essentially a macro that replayed the creation steps over the existing site definition. However, this isn’t the case with the new WSP format. The source of the items including content types is tracked, and may be removed if you remove the site template.

2 replies
  1. Todd Bleeker
    Todd Bleeker says:

    The reason for this is rooted in the change from an STP file to a sandboxed WSP CAB. The 2003/2007 STP was simply a “macro” on top of one of the existing Site Definitions on the Farm. So, new sites provisioned from an STP were dependent on the Site Definition, thus the STP was no longer needed.
    In 2010, the Site Template WSP is actually a custom Site Definition. So, new sites provisioned from from a WSP are dependent on the WSP’s Site Definition, thus the need for the WSP to remain activated.

  2. alandoland
    alandoland says:

    It was quick enough to find a Microsoft KB article (825791) for CS0016. It points to the fact that there may be a bad TMP or TEMP directory setting. We went into the service mcpd and manually set the TMP and TEMP variables in the profile. However, the problem didn’t go away.

Comments are closed.