4

This issue is related to this post.

I get an error message when the publishing feature is activated on sites of certain types. This means that I also get an error message when I create certain sites that are dependent on the Publishing Feature (and thereby activate the feature on site creation) e.g. Enterprise Wiki.

In my ULS-log, I see that the publishing feature is being activated. When it's almost done (after the event LRO - Starting background thread, job=Updating available web templates, this=50934842), it goes for another publishing provisioning taks, but it returns the following exception:

InitializePublishingWebDefaults failed. Microsoft.SharePoint.SPException: The object specified does not belong to a list.    
at Microsoft.SharePoint.SPWeb.GetItem(String strUrl, Boolean bFile, Boolean cacheRowsetAndId, Boolean bDatesInUtc, String[] fields)    
 at Microsoft.SharePoint.SPFile.get_Item()    
 at Microsoft.SharePoint.Publishing.MasterUrlProperty.SetDirectValue(String value, SPWeb web)    
 at Microsoft.SharePoint.Publishing.InheritableProperty`1.SetInherit(Boolean inherit, Boolean forceAllSubWebInherit, String successUrl, String failureUrl, Boolean& updateRequired)    
 at Microsoft.SharePoint.Publishing.InheritableProperty`1.SetInherit(Boolean inherit, Boolean forceAllSubWebInherit, Boolean& updateRequired)    
 at Microsoft.SharePoint.Publishing.Internal.AreaProvisioner.SetMasterPageProperties(PublishingWeb area, Boolean& updateRequired)    
 at Microsoft.SharePoint.Publishing.Internal.AreaProvisioner.SetLayoutRelatedProperties(PublishingWeb area, Boolean& updateRequired)    
 at Microsoft.SharePoint.Publishing.Internal.AreaProvisioner.InitializePublishingWebDefaults()

and after that the following error message is shown / logged:

Event log message was: 'Failed to initialize some site properties for Web
 at Url: 'http://local/entwiki''. Exception was: 'Microsoft.SharePoint.SPException: The object specified does not belong to a list.    
 at Microsoft.SharePoint.SPWeb.GetItem(String strUrl, Boolean bFile, Boolean cacheRowsetAndId, Boolean bDatesInUtc, String[] fields)    
 at Microsoft.SharePoint.SPFile.get_Item()    
 at Microsoft.SharePoint.Publishing.MasterUrlProperty.SetDirectValue(String value, SPWeb web)    
 at Microsoft.SharePoint.Publishing.InheritableProperty`1.SetInherit(Boolean inherit, Boolean forceAllSubWebInherit, String successUrl, String failureUrl, Boolean& updateRequired)    
 at Microsoft.SharePoint.Publishing.InheritableProperty`1.SetInherit(Boolean inherit, Boolean forceAllSubWebInherit, Boolean& updateRequired)    
 at Microsoft.SharePoint.Publishing.Internal.AreaProvisioner.SetMasterPageProperties(PublishingWeb area, Boolean& updateRequired)    
 at Microsoft.SharePoint.Publishing.Internal.AreaProvisioner.SetLayoutRelatedProperties(PublishingWeb area, Boolean& updateRequired)    
 at Microsoft.SharePoint.Publishing.Internal.AreaProvisioner.InitializePublishingWebDefaults()'

The strange thing is that this only happens when I use my custom master. I have a feature which loops through all the webs in a sc and applies this method:

public static void ApplyBrandingMaster(SPWeb web)
        {
            Uri masterUri = new Uri(web.Site.RootWeb.Url + "/_catalogs/masterpage/custom_main.master");
            web.MasterUrl = masterUri.AbsolutePath;
            web.CustomMasterUrl = masterUri.AbsolutePath;
            web.Update();
        }

It seems that if the master is NOT applied, there is no error. What could be wrong? I don't see how the master and the publishing feature are related this way.

3
  • How do you provision your custom_main.master file? programmatically/with Elements.xml/upload to masterpage gallery manually? Commented May 2, 2011 at 11:26
  • Using Elements.xml<Module Name="MasterPages"> <File Path="MasterPages\custom_main.master" Url="_catalogs/masterpage/custom_main.master" /> </Module>
    – tarjeieo
    Commented May 2, 2011 at 11:43
  • the Url is wrong Commented May 16, 2011 at 9:55

3 Answers 3

4

Please, try to add List="116" attribute to your Module element, as it is shown in this MSDN how-to:

http://msdn.microsoft.com/en-us/library/ms441170.aspx

<Module Name="MasterPages" List="116" Url="_catalogs/masterpage"> 
  <File Path="MasterPages\custom_main.master" Url="custom_main.master" /> 
</Module>
4
  • Thanks! It works. I also added "Type="GhostableInLibrary" at the same time, but that shouldn't matter.
    – tarjeieo
    Commented May 2, 2011 at 12:56
  • Weird - It doesn't work on the server, just local on my machine. One weird thing is that the master doesn't show in the master page gallery on the server, only on my machine. :S
    – tarjeieo
    Commented May 3, 2011 at 8:50
  • So, do you keep getting the same error on server, or you got another error? Maybe it's just something like a cache? Have you done iisreset or reboot? Commented May 3, 2011 at 9:22
  • Reboot and iisreset didn't fix it. I fixed the problem by opening the masterpage folder in SP Designer and deleting the master page from there. When I activated the feature again, it correctly deployed the file to the master page gallery (with List=116 applied to it). Thanks for the help
    – tarjeieo
    Commented May 3, 2011 at 9:44
1

I ran into this same problem and it turned out that the person creating the subsite didn't have the proper permission to get access to the Master Page Gallery in the root of the site collection, where my master page lived, because we had created an alternate Restricted Readers group. You can read a more thorough explanation of the problem (and my particular solution) here: http://blog.beckybertram.com/Lists/Posts/Post.aspx?ID=181.

1

programatically activate Publishing features in site level and web level. this will help you to solve this issue.

Following two methods can use to activate Site collection and web features.

        public static void ActivateSiteCollectionFeatures(SPWeb web, string featureId)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(web.Url))
                {
                    using (SPWeb newWeb = site.OpenWeb())
                    {
                        newWeb.AllowUnsafeUpdates = true;
                        SPFeatureCollection featureCollection = newWeb.Site.Features;
                        featureCollection.Add(new Guid(featureId), true);
                        newWeb.Update();
                        newWeb.AllowUnsafeUpdates = false;

                    }
                }
            });
        }

        public static void ActivateWebFeatures(SPWeb web, string featureId)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(web.Url))
                {
                    using (SPWeb newWeb = site.OpenWeb())
                    {
                        newWeb.AllowUnsafeUpdates = true;
                        SPFeatureCollection featureCollection = newWeb.Features;
                        featureCollection.Add(new Guid(featureId), true);
                        newWeb.Update();
                        newWeb.AllowUnsafeUpdates = false;

                    }
                }
            });
        }
1
  • Some more information, ie on how to programmatically active publishing will help in this case.
    – Hugh Wood
    Commented Nov 22, 2012 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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