We were getting “Trying to use an SPWeb object that has been closed or disposed and is no longer valid.” in our MOSS -Workflow project.
After investigating all the source codes, I found the error causing statement in WebPart class.
The best practice is to dispose objects either by calling Dispose() in finally block or with using clause.
The snippet causing problem in our project was
using (SPWeb web = SPContext.Current.Web)
group = web.Groups[“Administrators”];
this.DisplayText = "Submit for Approval";
Here, the object is not really created in the memory, only the reference to the exisiting object is got and used. We should not dispose the current context web object manually in our code.
More information about best practice can be found at
Happy Coding :)