的實例,我有以下激活碼:「激活功能」:對象引用未設置到對象
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
// Create a new list and populate it.
using (SPWeb web = properties.Feature.Parent as SPWeb)
{
web.Lists.Add("Projects", "Projects That are currently being worked on.", SPListTemplateType.GenericList);
web.Update();
// Add the new list and the new content.
SPList projectList = web.Lists["Projects"];
projectList.Fields.Add("Name", SPFieldType.Text, false);
projectList.Fields.Add("Description", SPFieldType.Text, false);
projectList.Update();
//Create the view? - Possibly remove me.
System.Collections.Specialized.StringCollection stringCollection =
new System.Collections.Specialized.StringCollection();
stringCollection.Add("Name");
stringCollection.Add("Description");
//Add the list.
projectList.Views.Add("Project Summary", stringCollection, @"", 100,
true, true, Microsoft.SharePoint.SPViewCollection.SPViewType.Html, false);
projectList.Update();
}
}
哪些應該通過並添加新的列表稱爲項目及其相關視圖。如何過上運行的應用程序時,我得到:
「激活功能」:對象引用不設置到 對象的實例
我的問題是:
- 這是爲什麼發生了什麼?激活發生在站點級別。我是「開發」網站的「admin」。
- 我應該每次檢查以確保此列表不存在? (每次,指每次我打部署)
哪條線拋出異常?這應該是絕對的第一件事,你應該把它包括在問題中。 –
它實際上並沒有說哪一行,它是0行,0行,0行,CustomerCommunicationProject。 @jonSkeet – TheWebs
您沒有完整的堆棧跟蹤?伊克。你能通過調試器中的代碼嗎? (如果你當前正在運行Release版本,請試試Debug版本,這可能會給你更多的信息。) –