Wednesday, 24 December 2014

Office 365: Exception while activating publishing feature - Feature with Id ' ' is not installed in this farm, and cannot be added to this scope.

Hi All,

It’s again long time, busy with project, but continued on office 365 side. Sharing one small finding but could save your timeJ.

One of our requirements is to activate the publishing feature (“SharePoint Server Publishing Infrastructure”) on our one of the site collection which is of type Team site.
 

So we have CSOM + PowerShell approach and used following CSOM code to activate the features using PowerShell script

#getting all site features

$siteFeatures = $clientContext.Site.Features
$clientContext.Load($siteFeatures)
$clientContext.ExecuteQuery()

#activating “SharePoint Server Publishing Infrastructure” feature

$featureId = “f6924d36-2fa8-4f0b-b16d-06b7250180fa”
$fId = [GUID]$featureId
$siteFeatures.Add($fId, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::Site)
$clientContext.ExecuteQuery()

As soon as above code executed we got the following error

An error occurred activating Feature. Error detail: Exception calling "ExecuteQuery" with "0" argument(s): "Feature with Id 'f6924d36-2fa8-4f0b-b16d-06b7250180fa' is not installed in this farm, and cannot be added to this scope.”


After digging a lot and went through couple of blogs, noticed that, in some blogs FeatureDefinitionScope is set to None. We tried this option and it worked like charmJ.

So it looks like as

$siteFeatures.Add($fId, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)

For now I am not sure is this bug or it works in this way but I really wondered why so this since there are 4 scopes in FeatureDefinitionScope enumeration as


using System;
namespace
 Microsoft.SharePoint.Client
{
    public enum
 FeatureDefinitionScope
    {
        None,
        Farm,
        Site,
        Web
    }
}


I then tried with the web level feature but same error and then it worked with None option.

Summary:


While activating feature using CSOM it doesn’t accept respective scope (Site or Web), we need to provide feature definition scope as None.Thanks!

Enjoy reading :)

Feel free to comment / feedback if any :)


 


No comments: