Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED))

Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED))


When working with visual webpart control, my visual webpart works fine, but when i deploy the more then one Visual webpart on a single page, it gives me above error, while going in to many forums and reading the blogs, i was wondering there is some thing with my code and the SPSite and SPWeb object disposal.

i used to write the code like this

using (SPSite site =SPContext.Current.Site)
{

using (SPWeb web = site.RootWeb)
{

// your code

}

}

though i am scoping the object rightly(using automatically dispose the object the routine gets outside the scope), but there is still some thing missing, after some time i figured out that the problem is with SPContext object rather than SPsite object, because once it dispose in one Visual Webpart, it can not be acquired back, so i change the code like this

using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{

using (SPWeb web = site.RootWeb)
{

// your code

}

}

and do use the using scope, it will save you from explicitly disposing the objects 😀

using (SPSite site = new SPSite(SPContext.Current.Site.Url))

using (SPWeb web = site.RootWeb)
{

Advertisements

About Shakir Majeed

I am SharePoint certified Specialist, SharePoint Trainer, Techie Speaker. I am in-list of Speakers on SharePoint from Microsoft Innovation Center Karachi Pakistan. I am User Group Leader of SharePoint Techies User Group(STUG), View all posts by Shakir Majeed

23 responses to “Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED))

  • Ankur

    Hi,

    I am geting this error. Tried above method for dispose, but did’nt work out. Can you please look into this.

    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 File: c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\5bb91b38\bcc3e778\App_Web_rootwelcome.aspx_606526083.jfewljhu.0.cs Line: 0

  • Gaurav Goyal

    I was getting same error. But It solved my problem.
    Good.

  • JAML

    This helped me a lot. Thank you very much. I fixed my issue like this.

  • vamshi

    I am still facing the same problem while executing spsite dataquery.

  • Bruno

    Could you help me…

    void Page_Load(object sender, System.EventArgs e)
    {
    //SPWeb web = SPContext.Current.Web;

    try
    {

    CDOC.SharePoint.OrganizationalTree.UserProfile userProfile = CDOC.SharePoint.OrganizationalTree.Organization.GetProfile(ref web);

    if (!userProfile.Verify(CDOC.SharePoint.OrganizationalTree.ProfileType.UsuarioArea) && !userProfile.IsAdministrator)
    {
    Response.Redirect(“~/default.aspx”);
    }
    }
    catch { }
    }

    <SharePoint:EncodedLiteral runat="server" text="” EncodeMethod=”HtmlEncode”/>

    TD.ms-titleareaframe, .ms-pagetitleareaframe {
    height: 10px;
    }
    Div.ms-titleareaframe {
    height: 100%;
    }
    .ms-pagetitleareaframe table {
    background: none;
    height: 10px;
    }

    var navBarHelpOverrideKey = “wssmain”;

    .ms-bodyareaframe {
    padding: 0px;
    }

     

  • HelenC

    Excellent – that did the trick! Re-read about when to use using and I shouldn’t have been auto disposing the context – horrible error message

  • Mario

    Hi Shakir!

    You are my hero of the day. There were other sites which had a solution to this problem but none of them worked for me. You explained everything very well.

    Kudos,

    Mario

  • prafulla

    Thanks for article, it helps alot

  • sem

    I need help with the error below
    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.GetWebListPermMask(String bstrUrl, String bstrListName) +0
    Microsoft.SharePoint.Library.SPRequest.GetWebListPermMask(String bstrUrl, String bstrListName) +134

    [SPException: Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED))]
    Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) +27615618
    Microsoft.SharePoint.Library.SPRequest.GetWebListPermMask(String bstrUrl, String bstrListName) +225
    Microsoft.SharePoint.SPList.get_EffectiveBasePermissions() +102
    Microsoft.SharePoint.WebPartPages.WikiEditPage.OnPreRender(EventArgs e) +754
    System.Web.UI.Control.PreRenderRecursiveInternal() +108
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394

    *************************************Here is the code********************
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Microsoft.SharePoint;

    namespace wpSiteList.wpSiteListV1
    {
    public partial class wpSiteListV1UserControl : UserControl
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    try
    {
    SPSite mySite = SPContext.Current.Web.Site;
    using (SPSite oSite = mySite)
    {
    using (SPWeb oWeb = oSite.OpenWeb())
    {
    foreach (SPList oList in oWeb.Lists)
    {
    //Console.WriteLine(“Title: {0} Created: {1}”, oList.Title, oList.Created.ToString());
    lblMsg.Text += oList.Title.ToString() + “\n”;
    }

    }
    }
    }
    catch (Exception ex)
    {
    Response.Write(ex.Message);
    }
    }
    }
    }

    • Shakir Majeed

      Dear,

      Sorry for late reply, please replace the following code
      SPSite mySite = SPContext.Current.Web.Site;
      using (SPSite oSite = mySite)

      with below one

      string siteURL = SPContext.Current.Web.Url;
      using (SPSite oSite = new SPSite(siteURL)
      As it can be observed that i am OSite object from URL not from the Current context object.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: