Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 试图使用已不存在的对象。(HRESULT的例外:0x80030102(STG_E_已还原))_C#_Visual Studio_Visual Studio 2010_Sharepoint_Sharepoint 2010 - Fatal编程技术网

C# 试图使用已不存在的对象。(HRESULT的例外:0x80030102(STG_E_已还原))

C# 试图使用已不存在的对象。(HRESULT的例外:0x80030102(STG_E_已还原)),c#,visual-studio,visual-studio-2010,sharepoint,sharepoint-2010,C#,Visual Studio,Visual Studio 2010,Sharepoint,Sharepoint 2010,我正试图通过编程方式将新的ListItem添加到SharePoint 2010网站中已经存在的列表中 我已经创建了一个新的Web部件,并使用以下事件处理程序添加了一个按钮 protected void Unnamed1_Click(object sender, EventArgs e) { using (SPSite currentSiteCollection = new SPSite(SPContext.Current.Site.ID)) {

我正试图通过编程方式将新的ListItem添加到SharePoint 2010网站中已经存在的列表中

我已经创建了一个新的Web部件,并使用以下事件处理程序添加了一个按钮

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

    }
已将我的Web部件添加到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

我在论坛和谷歌上尝试了几种解决方案,但都没有成功。

当我的列表定义中包含
元素时,我遇到了这个问题

更新:
如果我有一个不允许空值的
,并且在创建列表项时未将此字段设置为有效值之一,则会出现此问题。

我在SharePoint 2010中的一个子站点的每个列表视图上以及默认视图上都出现此错误。结果是,用户将站点区域设置中的一个时区更改为另一个时区(+8),我将其更改回原来的时区后,所有的时区都重新开始工作)

您尝试过:

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

请不要在标题前加上“Sharepoint 2010”之类的前缀。这就是标记的作用。使用“是/否”字段更新项目而不设置值时的相同行为。因为类型是bool,所以很混乱?ie可为null,并且该字段在SP中是可选的。不过,该字段在架构中定义了默认值。