试图使用已不复存在的对象。 (来自HRESULT的异常:0x80030102(STG_E_REVERTED))

时间:2012-02-07 15:28:41

标签: c# visual-studio visual-studio-2010 sharepoint sharepoint-2010

我正在尝试以编程方式将新的ListItem添加到SharePoint 2010网站中已存在的列表中。

我创建了一个新的webpart,使用以下事件处理程序为其添加了一个按钮

    protected void Unnamed1_Click(object sender, EventArgs e)
    {
        using (SPSite currentSiteCollection = new SPSite(SPContext.Current.Site.ID))
        {
            using (SPWeb currentWebsite = currentSiteCollection.OpenWeb(SPContext.Current.Web.ID))
            {
                SPListItem myNewItem = currentWebsite.Lists["myList"].AddItem();
                myNewItem["Title"] = "newItem1";
                myNewItem.Update();
            }
        }

    }

将我的webpart添加到sharepoint 2010网站的默认页面...不幸的是,当我点击按钮时出现此错误

    Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED))
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED))

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[COMException (0x80030102): Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED))]
   Microsoft.SharePoint.Library.SPRequestInternalClass.SetDisableAfterEvents(Boolean bNewDisableAfterEvents) +0
   Microsoft.SharePoint.Library.SPRequest.SetDisableAfterEvents(Boolean bNewDisableAfterEvents) +124

[SPException: Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED))]
   Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) +27677298
   Microsoft.SharePoint.Library.SPRequest.SetDisableAfterEvents(Boolean bNewDisableAfterEvents) +207
   Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents, String filename) +26793884
   Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents, String filename) +26793214
   Microsoft.SharePoint.SPListItem.Update() +161
   SLBWOA.Web.UCNewChecklist.UCNewChecklistUserControl.Unnamed1_Click(Object sender, EventArgs e) +259
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

我已经在论坛上通过谷歌尝试了几种解决方案,但没有运气。

3 个答案:

答案 0 :(得分:1)

当我的列表定义包含<Field Type="Choice">里面有<Default>元素时,我遇到了这个问题。

<强>更新 如果我有<Field Type="Choice">不允许空值,则会出现此问题,并且在创建列表项时,我不将此字段设置为其中一个有效值。

答案 1 :(得分:0)

我在SharePoint 2010中的一个子网站中的每个列表视图上都出现此错误,默认视图也是如此。事实证明,用户将站点区域设置中的时区更改为另一个时区(+8),在我将其更改后,所有时区再次开始工作)

答案 2 :(得分:0)

你有没有尝试过:

    protected void Unnamed1_Click(object sender, EventArgs e)
{
    SPSite currentSiteCollection = SPContext.Current.Site;
    using (SPWeb currentWebsite = currentSiteCollection.OpenWeb(SPContext.Current.Web.ID))
    {
        SPListItem myNewItem = currentWebsite.Lists["myList"].AddItem();
        myNewItem["Title"] = "newItem1";
        myNewItem.Update();
    }
}