Monday, June 23, 2014

Common Error: The site is not valid. The 'Pages' document library is missing.

The site is not valid. The 'Pages' document library is missing.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.SharePoint.Publishing.InvalidPublishingWebException: The site is not valid. The 'Pages' document library is missing.
The interesting piece here is that the Pages library indeed existed but could not be found.
Background Information
To understand this we need to look into how the Publishing feature find the Pages library in a Publishing site. As the Pages library does not need to have the name "Pages" - e.g. in German version it has the name "Seiten" SharePoint does not search for the Pages library by name.
Instead the Publishing feature stores the unique ID of the Pages library in the __PagesListId property which resides in the property bag of the publishing site.
The above listed error will occur if the value stored in the __PagesListId does not match the ID of the actual Pages library.
What can cause this problem?
Honestly: I don't know. I have not managed to forcefully cause such an inconsistency - if one of you has repro steps, please post a comment here!
How to fix the problem?
To fix the issue it is required to update the value of the __PagesListId property value to match the ID of the Pages library.
This can be done (e.g.) through the following Powershell script:


$web = get-spweb http://site-collection/path-to-affected-site
$correctId = $web.Lists["Pages"].ID
$web.AllProperties["__PagesListId"] = $correctId.ToString()
$web.Update()