Thursday, September 18, 2008

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

This is one is an olddie but it's never too much, when using SPWeb and SPSite, you should remember the Context, so when doing

using (SPWeb web = SPContext.Current.Web)
{
...
}

You will get a nice "Trying to use an SPWeb object that has been closed or disposed and is no longer valid" because you are disposing an object you really didnt create.

Best practices here.

No comments: