This project is read-only.
1

Resolved

SPWeb object possibly closed too soon

description

I get a lot of errors in my logs from this webpart suggesting that a SPWeb object is being disposed too early. I am using v193 and may upgrade soon.
 
Detected use of SPRequest for previously closed SPWeb object. Please close SPWeb objects when you are done with all objects obtained from them, but not before. Stack trace: at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData() at Microsoft.SharePoint.SPListItemCollection.GetEnumerator() at System.Linq.Enumerable.d__aa1.MoveNext() at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext() at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source) at CalendarWebpart.CalendarWebpart.cal_DayRender(Object sender, DayRenderEventArgs e) at System.Web.UI.WebControls.Calendar.OnDayRender(TableCell cell, CalendarDay day) at System.Web.UI.WebControls.Calendar.RenderDays(HtmlTextWriter writer, DateTime firstDay, DateTime visibleDate,... 435d955b-977e-4f10-9b94-1d8115a0e5b8
07/08/2011 04:20:20.23* w3wp.exe (0x0C60) 0x0A94 SharePoint Foundation General 90hv Unexpected ... CalendarSelectionMode selectionMode, Boolean buttonsActive, Boolean useAccessibleHeader) at System.Web.UI.WebControls.Calendar.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) at Microsoft.SharePoint.WebPartPages.WebPart.RenderWebPart(HtmlTextWriter output) at CalendarWebpart.CalendarWebpart.RenderWebPart(HtmlTextWriter output) at Microsoft.SharePoint.WebPartPages.WebPart.Render(HtmlTextWriter writer) at Microsoft.SharePoint.WebPartPages.SPChrome.RenderPartContents(HtmlTextWriter output, WebPart part) at Microsoft.SharePoint.WebPartPag... 435d955b-977e-4f10-9b94-1d8115a0e5b8
07/08/2011 04:20:20.23* w3wp.exe (0x0C60) 0x0A94 SharePoint Foundation General 90hv Unexpected ...es.SPChrome.RenderWebPart(HtmlTextWriter output, WebPart part) at Microsoft.SharePoint.WebPartPages.WebPartZone.RenderZoneCell(HtmlTextWriter output, Boolean bMoreParts, WebPart part) at Microsoft.SharePoint.WebPartPages.WebPartZone.RenderWebParts(HtmlTextWriter output, ArrayList webParts) at Microsoft.SharePoint.WebPartPages.WebPartZone.Render(HtmlTextWriter output) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.HtmlControls.HtmlForm... 435d955b-977e-4f10-9b94-1d8115a0e5b8
07/08/2011 04:20:20.23* w3wp.exe (0x0C60) 0x0A94 SharePoint Foundation General 90hv Unexpected ....RenderChildren(HtmlTextWriter writer) at System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) at System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Page.Render(HtmlTextWriter writer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean inclu... 435d955b-977e-4f10-9b94-1d8115a0e5b8
07/08/2011 04:20:20.23* w3wp.exe (0x0C60) 0x0A94 SharePoint Foundation General 90hv Unexpected ...deStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.DEFAULT_ASPX__1880612465.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error) at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) at System.Web.Hosting.PipelineRuntime.ProcessRequ... 435d955b-977e-4f10-9b94-1d8115a0e5b8
07/08/2011 04:20:20.23* w3wp.exe (0x0C60) 0x0A94 SharePoint Foundation General 90hv Unexpected ...estNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) 435d955b-977e-4f10-9b94-1d8115a0e5b8
07/08/2011 04:20:20.30 w3wp.exe (0x0C60) 0x0A94 SharePoint Foundation Monitoring b4ly High Leaving Monitored Scope (EnsureListItemsData). Execution Time=61.301872 435d955b-977e-4f10-9b94-1d8115a0e5b8

comments

Hikmer wrote Jul 8, 2011 at 3:09 PM

I checked your code and you are disposing an SPContext item with a using clause, it isn't required. http://msdn.microsoft.com/en-us/library/ms778813.aspx#Y9365 Yeah it's confusing and yeah I did it too....

SPContext objects are managed by the SharePoint framework and should not be explicitly disposed in your code. This is true also for the SPSite and SPWeb objects returned by SPContext.Site, SPContext.Current.Site, SPContext.Web, and SPContext.Current.Web.

nsergiu wrote Dec 24, 2011 at 9:02 PM

Check the last release, 1.9.5, i made some changes to solve this.

nsergiu wrote Aug 3, 2012 at 2:29 PM

Check the release 1.9.5.1, it should be better

wrote Jan 28, 2013 at 3:58 PM

wrote Feb 14, 2013 at 9:14 PM

wrote May 16, 2013 at 10:53 AM

wrote May 16, 2013 at 10:53 AM

wrote Jun 14, 2013 at 8:16 AM