SharePoint 2010 - 尝试使用 SPWebConfigModification 时收到错误 [英] SharePoint 2010 - Receiving error attempting to use SPWebConfigModification

查看:41
本文介绍了SharePoint 2010 - 尝试使用 SPWebConfigModification 时收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 SharePoint 功能,并在我的 FeatureReceiver 中尝试添加一个 SPWebConfigModification.我一直在遵循 这篇 博文.

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();
}

这是在 SharePoint ULS 查看器中看到的错误堆栈跟踪:

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)

在更新过程中的某处,一个空路径在 XPath 表达式中被引用.这不是我的功能.有什么想法吗?

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

推荐答案

就我而言,wappCurrent.WebConfigModifications 有一些旧值和无效的 Path 属性.清除数组解决了问题.

In my case, wappCurrent.WebConfigModifications had some old values with an invalid Path property. Clearing the array fixed the problem.

这篇关于SharePoint 2010 - 尝试使用 SPWebConfigModification 时收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆