SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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 '11 at 5:48
up vote 0 down vote accepted

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.

share|improve this answer

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


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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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