我正在编写特征激活代码的代码。但是当我尝试通过VS 2010部署我的解决方案时,它表示部署功能激活的错误错误:对象引用未设置为对象的实例。
我无法调试,因为它不允许我部署代码。 我试图放入

System.Diagnostics.Debugger.Break();
.

在我的功能开始的方法开始。 有什么想法吗?

  public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            using(SPSite spSite = new SPSite(HttpContext.Current.Request.Url.ToString()))
           {
                using(SPWeb spWeb = spSite.OpenWeb())
                {

                }

           }
        }
.

有帮助吗?

解决方案

Visual Studio 2010的说明:

单击菜单中的“项目”,然后单击“属性”

单击“左侧的SharePoint,然后将活动部署配置切换为”无激活“。

开始调试,然后通过UI手动激活功能。如果您正确设置了断点,您现在应该能够通过您的功能激活步骤进行调试。

其他提示

如果您的功能是Scened,则可以获取Spsite对象如下:

var spSite = properties.Feature.Parent as SPSite;
.

如果您的功能是Web范围,您可以获取SPSITE对象如下:

var spSite = (properties.Feature.Parent as SPWeb).Site;
.

许可以下: CC-BY-SA归因
scroll top