none
Trying to use an SPWeb object that has been closed or disposed and is no longer valid.

    Question

  • Hi,

    We have a custom master page designed in sharepoint designer and we have a custom web part. We are using the master page and this custom web part in a share point page. It was working earlier and all of a sudden it gives the following error.

    Trying to use an SPWeb object that has been closed or disposed and is no longer valid

    We checked the code and we are not using any SPSite or SPWeb within the code. More over its plain ASP.Net code to send an email and it doesn't contains any using block.

    Only change in the system is my admin configured the Alternate Access Mapping within the Central Admin.

    What would be the issue? In that page we don't have anything else. (No other custom web parts).

    Thank you


    Kathir


    • Edited by karurkathir Tuesday, June 05, 2012 11:56 AM more info
    Tuesday, June 05, 2012 11:51 AM

Answers

  • I suggest you look through the ULS logs located at (by default) "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\logs" and search for "Trying to use an SPWeb Object that has been closed or disposed and is no longer valid".  Optionally you can get the ULS Viewer, http://archive.msdn.microsoft.com/ULSViewer

    I would focus on

    1.  Is Central Administration somehow misconfigured (e.g. the farm can't find it) causing the above error message to be thrown

    2. What else is on the page with your masterpage with the webpart.  There could be a control on the page reference a static or shared SPWeb object that has been disposed.

    If the error is accurate, someone something has a reference to an SPWeb object that has been disposed and it's still trying to use it.  Reset IIS and see if you get the same error (resetting iis will cause the processes to reset, causing all references in memory to be lost creating new ones).

    It could be a million things.  A master page is complex in sharepoint there is a lot on it.  And there is always code running that has nothing to do with the master page.  E.g. Authentication on a claims web application.  You log in, you get authenticated, and any claim providers configured on the farm try to resolve you, any one of those could be trying to use a Disposed SPWeb.

    So the main question is, have you customized anything on the server other than that 1 masterpage and 1 webpart?  If not I would lean towards the change on the alternate access mapping in central administration.


    My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction

    • Marked as answer by karurkathir Wednesday, June 06, 2012 5:48 AM
    Tuesday, June 05, 2012 6:14 PM
  • Hi

    Even if you haven't used any using statements or created new SPWeb objects, there is still the default  SPContext.Current.Web which is always there when a site page is open. So you should check the code to see if this object is referenced in your code and eventually how it is treated. 

    You can also try using the SPDisposeCheck tool in your VS environment to test the web part code for any unknown or unintentioned disposals.   http://archive.msdn.microsoft.com/SPDisposeCheck


    Kind Regards Bjoern
    Blog



    Tuesday, June 05, 2012 8:48 PM
    Moderator

All replies

  • I suggest you look through the ULS logs located at (by default) "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\logs" and search for "Trying to use an SPWeb Object that has been closed or disposed and is no longer valid".  Optionally you can get the ULS Viewer, http://archive.msdn.microsoft.com/ULSViewer

    I would focus on

    1.  Is Central Administration somehow misconfigured (e.g. the farm can't find it) causing the above error message to be thrown

    2. What else is on the page with your masterpage with the webpart.  There could be a control on the page reference a static or shared SPWeb object that has been disposed.

    If the error is accurate, someone something has a reference to an SPWeb object that has been disposed and it's still trying to use it.  Reset IIS and see if you get the same error (resetting iis will cause the processes to reset, causing all references in memory to be lost creating new ones).

    It could be a million things.  A master page is complex in sharepoint there is a lot on it.  And there is always code running that has nothing to do with the master page.  E.g. Authentication on a claims web application.  You log in, you get authenticated, and any claim providers configured on the farm try to resolve you, any one of those could be trying to use a Disposed SPWeb.

    So the main question is, have you customized anything on the server other than that 1 masterpage and 1 webpart?  If not I would lean towards the change on the alternate access mapping in central administration.


    My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction

    • Marked as answer by karurkathir Wednesday, June 06, 2012 5:48 AM
    Tuesday, June 05, 2012 6:14 PM
  • Hi

    Even if you haven't used any using statements or created new SPWeb objects, there is still the default  SPContext.Current.Web which is always there when a site page is open. So you should check the code to see if this object is referenced in your code and eventually how it is treated. 

    You can also try using the SPDisposeCheck tool in your VS environment to test the web part code for any unknown or unintentioned disposals.   http://archive.msdn.microsoft.com/SPDisposeCheck


    Kind Regards Bjoern
    Blog



    Tuesday, June 05, 2012 8:48 PM
    Moderator