2

UPDATED: This occurs sometimes, so not only just once after web app recycle.

I'm getting publishing page layouts with the code below, before creating publishing pages to site "hxxp://myportal/m/1/aaa" (where "m" is wildcard managed path, and "hxxp://myportal/m/1" is site collection, and "aaa" is subsite). Code is located in custom Visual Web Part.

using (var subsite = new SPSite("http://myportal/m/1/aaa"))
{
   using (var subWeb = subsite.OpenWeb())
   {
      PublishingWeb publishingSubWeb = PublishingWeb.GetPublishingWeb(subWeb);

      /* Search for the page layout for creating the new page */
      var layouts = new List<PageLayout>(publishingSubWeb.GetAvailablePageLayouts());

     //...
   }    
}

Every now and then I get the error below. It always occurs whenever the code is run the FIRST time after web app recycle or iisreset, but also some other times. Haven't found any real logic why it occurs (some race condition, maybe?).

So GetAvailablePageLayouts() gives error:

<nativehr>0x80070002</nativehr><nativestack></nativestack>There is no Web named "/m/1".
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: System.IO.FileNotFoundException: <nativehr>0x80070002</nativehr><nativestack></nativestack>There is no Web named "/m/1".

Source Error:    
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:
[FileNotFoundException: <nativehr>0x80070002</nativehr><nativestack></nativestack>There is no Web named "/m/1".]
   Microsoft.SharePoint.Library.SPRequestInternalClass.OpenWebInternal(String bstrUrl, Guid& pguidID, String& pbstrRequestAccessEmail, UInt32& pwebVersion, String& pbstrServerRelativeUrl, UInt32& pnLanguage, UInt32& pnLocale, String& pbstrDefaultTheme, String& pbstrDefaultThemeCSSUrl, String& pbstrThemedCssFolderUrl, String& pbstrAlternateCSSUrl, String& pbstrCustomizedCssFileList, String& pbstrCustomJSUrl, String& pbstrAlternateHeaderUrl, String& pbstrMasterUrl, String& pbstrCustomMasterUrl, String& pbstrSiteLogoUrl, String& pbstrSiteLogoDescription, Object& pvarUser, Boolean& pvarIsAuditor, Int32& plSiteFlags, Boolean& pbOverwriteMUICultures, Boolean& pbMUIEnabled, String& pbstrAlternateMUICultures, Int32& puiVersion, Int16& pnClientTag) +0
   Microsoft.SharePoint.Library.SPRequest.OpenWebInternal(String bstrUrl, Guid& pguidID, String& pbstrRequestAccessEmail, UInt32& pwebVersion, String& pbstrServerRelativeUrl, UInt32& pnLanguage, UInt32& pnLocale, String& pbstrDefaultTheme, String& pbstrDefaultThemeCSSUrl, String& pbstrThemedCssFolderUrl, String& pbstrAlternateCSSUrl, String& pbstrCustomizedCssFileList, String& pbstrCustomJSUrl, String& pbstrAlternateHeaderUrl, String& pbstrMasterUrl, String& pbstrCustomMasterUrl, String& pbstrSiteLogoUrl, String& pbstrSiteLogoDescription, Object& pvarUser, Boolean& pvarIsAuditor, Int32& plSiteFlags, Boolean& pbOverwriteMUICultures, Boolean& pbMUIEnabled, String& pbstrAlternateMUICultures, Int32& puiVersion, Int16& pnClientTag) +450
   Microsoft.SharePoint.SPWeb.InitWebPublic() +621
   Microsoft.SharePoint.SPWeb.get_LanguageCulture() +54
   Microsoft.SharePoint.SPWeb.get_Title() +33
   Microsoft.SharePoint.SPSite.OpenWeb(Guid gWebId, Int32 mondoHint) +699
   Microsoft.SharePoint.SPSite.OpenWeb(Guid gWebId) +34
   Microsoft.SharePoint.Publishing.CachedObjectFactory.OpenWebFromSuperUserSite(Guid webId) +154
   Microsoft.SharePoint.Publishing.CachedArea.CreateCachedArea(PublishingWeb area, CachedObjectFactory factory, String parentId) +168
   Microsoft.SharePoint.Publishing.CachedObjectFactory.CreateObject(PublishingWeb area, String parentUrl) +343
   Microsoft.SharePoint.Publishing.PublishingWeb.GetEffectiveAvailablePageLayoutsAsString() +54
   Microsoft.SharePoint.Publishing.PublishingWeb.GetAvailablePageLayouts() +59
   CreatePage.CPWebPart.CPWebPart.CreatePublishingPage(String subsiteUrl, String pageName, String pageLayoutName) +371
   CreatePage.CPWebPart.CPWebPart.createPage_Click(Object sender, EventArgs e) +144
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

Error occurs regardless of permissions users have on site "/m/1" or "/m/1/aaa" (so even site collection admins see it). All is good on both of the sites (publishing features activated, etc.), and everything works second time and subsequent times. I also can create publishing pages normally with browser and they work fine, so page layout/content types are set correctly. Both sites are created with OOB Publishing site template.

I have Aug 2013 CU installed.

Why is it complaining of the parent site when I use the subsite to get the page layouts? Any workaround for this? Thanks!

1

For reference to others, I had this exact same issue.

I was getting it in within a Console application on a specific environment, where I copied Publishing Pages from one site collection to another, iterating over a list of sources and destinations.

My utility also copied web parts, and for some reason I thought I had to Fake the SPContext (Google it, your first result is probably the same code I use).

It would work fine on one site (or, weirder, one page when I added some missing Dispose() calls), then throw the above error when processing the next site (or page) in the list.

Turns out that SPContext.Current seems to completely screw with the Publishing Framework's cache when you have two instances open and are doing things with PageLayouts, etc.

So if you get this when you are doing things with two instances of PublishingWeb, trying temporarily setting the HttpContext to null (which unsets SPContext.Current), and see if it resolves it.

Do something like this:

HttpContext ctx = HttpContext.Current;
HttpContext.Current = null;

// Do your stuff...

HttpContext.Current = ctx;
  • I reference "two instances" of PublishingWeb, I actually think this could happen if you create a PublishingWeb to a site collection that is different to HttpContext.Current. Either way, it breaks it somehow, so just set to null whilst you do your shizz then set it back. – James Love Oct 11 '14 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.