I'm trying to update web.config in SharePoint when the feature is activated. I have created Event receiver. The code inside receiver is:

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
        SPWebApplication webApp = (properties.Feature.Parent as SPSite).WebApplication;

        SPWebConfigModification modification = new SPWebConfigModification("mode", "system.web/customErrors");
        modification.Owner = "modifyAccountFeatureOwner";
        modification.Sequence = 0;
        modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute;
        modification.Value = "Off";         


When I'm deploying feature I have received the following error: "Error occurred in deployment step 'Activate Features': Expression must evaluate to a node-set."

What is wrong with this?

  • Welcome to SharePoint Stack Exchange! Please tag by feature or topic and not by version or product. This helps to attract more attention to your question and keep it relevant. See How do I use tags for general guidelines.
    – Alex Angas
    Sep 14, 2011 at 5:48

2 Answers 2


I think the error occurs on this line:

SPWebConfigModification modification = new SPWebConfigModification("mode", "system.web/customErrors");

And the problem is the second parameter


which is an XPath expression. And this expression seems to be incorrect, which means it does not select an existing node in the web.config file. It probably has to be:


Please note: I did not test this.


Add the following line after webApp.WebConfigModifications.Add(modification);


it clears all the non-required modifications from the object.

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.