You receive an access violation error message when you call the Dispose method or the Close method to close an SPSite object or an SPWeb object in SharePoint Portal Server 2003 and in Windows SharePoint Services (901259)



The information in this article applies to:

  • Microsoft Office SharePoint Portal Server 2003
  • Microsoft Windows SharePoint Services

SYMPTOMS

Consider the following scenario in Microsoft Office SharePoint Portal Server 2003 and in Microsoft Windows SharePoint Services. You want to close an SPSite object or an SPWeb object. To do this, you call the Dispose method or the Close method of the SPWeb class or of the SPSite class. When you call the Dispose method or the Close method, the server unexpectedly crashes. Additionally, you receive an access violation error message that is similar to the following:
[COMException (0x80020009): Exception occurred.] Microsoft.SharePoint.Library.SPRequestInternalClass.UpdateWebPartCache(String bstrWebUrl, Boolean bAllUsers, String bstrID, Byte[]& ppsaData, Boolean fOMCall) +0 Microsoft.SharePoint.Library.a.a(String A_0, Boolean A_1, String A_2, Byte[]& A_3, Boolean A_4) [SPException: Exception occurred.] Microsoft.SharePoint.Library.a.a(String A_0, Boolean A_1, String A_2, Byte[]& A_3, Boolean A_4) Microsoft.SharePoint.SPWebPartCollection.a(Guid A_0, Byte[] A_1, Storage A_2, Boolean A_3) Microsoft.SharePoint.SPWebPartCollection.b(Guid A_0, Byte[] A_1, Storage A_2) Microsoft.SharePoint.WebPartPages.WebPart.OnUnload(EventArgs e) System.Web.UI.Control.UnloadRecursive(Boolean dispose) +121 System.Web.UI.Control.UnloadRecursive(Boolean dispose) +74 System.Web.UI.Control.UnloadRecursive(Boolean dispose) +74 System.Web.UI.Control.UnloadRecursive(Boolean dispose) +74 System.Web.UI.Page.ProcessRequestCleanup() +24 System.Web.UI.Page.ProcessRequest() +215 System.Web.UI.Page.ProcessRequest(HttpContext context) +18 Microsoft.SharePoint.ApplicationRuntime.SharePointHandler.SPProcessRequest(HttpContext context) [ApplicationException: Exception of type System.ApplicationException was thrown.] Microsoft.SharePoint.ApplicationRuntime.SharePointHandler.SPProcessRequest(HttpContext context) Microsoft.SharePoint.ApplicationRuntime.SharePointHandler.SPProcessRequest(HttpContext context) Microsoft.SharePoint.ApplicationRuntime.SharePointHandler.ProcessRequest(HttpContext context) System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +179 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +87

CAUSE

This issue occurs if the SPWeb object or the SPSite object is a shared resource. For example, this issue occurs if the SPWeb object or the SPSite object is provided by the GetContext method in a Web Part. In scenarios where the SPWeb object or the SPSite object is provided by the GetContext method, you should not call the Dispose method or the Close method. The following sample code is an example of what not to do.
// Example of what not to do
//using (SPSite site = SPControl.GetContextSite (this.Context)) {
  // Code to perform a task
//}
 
// If you have to use a GetContext* method, let SharePoint dispose of 
// the object.  The object is a shared resource.
SPSite site = SPControl.GetContextSite (this.Context);
  // Code to perform a task
// site.Dispose ();  <-- Do not call the Dispose method or the Close method on a shared resource. Leave this line commented.

RESOLUTION

If you create your own SPWeb object or SPSite object, you can use the Dispose method or the Close method to close the object. However, if you have a reference to a shared resource, do not use the Dispose method or the Close method to close the object. In scenarios where you have a reference to a shared resource, such as when the objects are provided by the GetContext method, let SharePoint Portal Server 2003 and Windows SharePoint Services manage the object.

MORE INFORMATION

For more information about the Dispose method and Close method of the SPWeb class, visit the following Microsoft Web site: For more information about the Dispose method and Close method of the SPSite class, visit the following Microsoft Web site: For more information about the SharePoint Portal Server object model and the Windows SharePoint Services object model, see the Microsoft SharePoint Products and Technologies 2003 Software Development Kit (SDK). To view the SharePoint Products and Technologies 2003 SDK, visit the following Microsoft Web site:

Modification Type:MajorLast Reviewed:10/12/2005
Keywords:kberrmsg kbtshoot KB901259 kbAudDeveloper