0
var feature = spSite.Features.SingleOrDefault(sf => sf.Definition.DisplayName.ToLower().Equals(strFeatureName));//Error block
     if (feature != null)//if feature is activated
      {   
       spSite.Features.Remove(feature.DefinitionId);//deactivate feature
       spSite.Features.Add(feature.DefinitionId);//activate feature
      }

I am using this code to check for activated features using a windows forms app. It is working fine in local but showing object reference error in DEV machine. I suspect the first line might be causing the error.

Can anyone figure out what would be causing the error and a workaround for this?

0

Try below

var feature = null;
if(spSite.Features != null) {
    feature = spSite.Features.SingleOrDefault(f => (f.Definition != null && f.Definition.DisplayName != null && f.Definition.DisplayName.ToLower().Equals(strFeatureName));
}

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.