views:

80

answers:

3

I'm creating a SharePoint feature and within my FeatureReceiver I'm attempting to add a SPWebConfigModification. I've been following the approach outlined in this blog post.

Here is a snippet from my feature receiver:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    var webApp = (SPWebApplication)properties.Feature.Parent;

    var debugMode = new SPWebConfigModification
                    {
                        Path = "configuration/system.web/customErrors",
                        Name = "mode",
                        Value = "Off",
                        Sequence = 0,
                        Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute,
                        Owner = "MyWebConfigMods"
                    };

    webApp.WebConfigModifications.Add(debugMode); // <------ Error is thrown at this line
    webApp.WebService.ApplyWebConfigModifications();
    webApp.Update();
}

Here is the stack trace from the error as seen in the SharePoint ULS viewer:

Feature receiver assembly 'MyCompany.SharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxx', class 'MyCompany.SharePoint.Features.WebConfig.WebConfigFeatureReceiver', method 'FeatureActivated' for feature '3a07b91c-0968-4f14-b2bc-ae0e3f109cf9' threw an exception: System.Xml.XPath.XPathException: '' is an invalid expression.    
at MS.Internal.Xml.XPath.XPathScanner..ctor(String xpathExpr)    
at MS.Internal.Xml.XPath.XPathParser.ParseXPathExpresion(String xpathExpresion)    
at MS.Internal.Xml.XPath.QueryBuilder.Build(String query, Boolean allowVar, Boolean allowKey)    
at System.Xml.XPath.XPathExpression.Compile(String xpath, IXmlNamespaceResolver nsResolver)    
at System.Xml.XPath.XPathNavigator.Select(String xpath)    
at System.Xml.XmlNode.SelectSingleNode(String xpath)    
at Microsoft.SharePoint.Administration.SPWebConfigFileChanges.ApplyModificationsWebConfigXmlDocument(XmlDocument xdWebConfig, String filepath)    
at Microsoft.SharePoint.Administration.SPWebApplication.ApplyWebConfigModifications()    
at Microsoft.SharePoint.Administration.SPWebService.ApplyWebConfigModifications()    
at MyCompany.SharePoint.WebConfigModificationFeatureReceiver.FeatureActivated(SPFeatureReceiverProperties properties)    
at Microsoft.SharePoint.SPFeature.DoActivationCallout(Boolean fActivate, Boolean fForce)

Somewhere during the update an empty path is being referenced within an XPath expression. It's not in my feature. Any ideas?

A: 

customErrors does not have an attribute named debug, you must be referring to compilation element

Vladi Gubler
@Vladi Gubler - Sorry, my sample was incorrect. I've updated it, but I still am facing the same error.
Wallace Breza
it looks OK to me, can you do other changes to the werb.config from the same feature? It seems not to find the correct element, but I can't see why...
Vladi Gubler
@Vladi Gubler - No, no modifications seem to work. I've tried other simple changes, like adding an element in `<appSettings />`.
Wallace Breza
I will post the code we use tomorrow. I cannot see any problem with your code, but this could be something real simple, like XPath namespace or something
Vladi Gubler
A: 

I have similar problem. Any ideas?

Alex
@Alex - You should add this as a comment rather than an answer.
Wallace Breza
A: 

This is the code we use:

                SPWebApplication wappCurrent = (SPWebApplication)properties.Feature.Parent;
                SPWebConfigModification modAuthorizedType = new SPWebConfigModification();
                modAuthorizedType.Name = "authorizedType[@Assembly='Infowise.AssociatedTasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=23853b1f8d5855a5']";
                modAuthorizedType.Owner = "Infowise.Actions";
                modAuthorizedType.Path = "configuration/System.Workflow.ComponentModel.WorkflowCompiler/authorizedTypes";
                modAuthorizedType.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
                modAuthorizedType.Value = @"<authorizedType Assembly=""Infowise.AssociatedTasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=23853b1f8d5855a5"" Namespace=""Infowise.Sharepoint.V3.Fields.Workflow"" TypeName=""*"" Authorized=""True"" />";
                wappCurrent.WebConfigModifications.Add(modAuthorizedType);
                wappCurrent.Update();
                wappCurrent.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();

Hope if helps

Vladi Gubler