I had quite a weird error, when deleting a webpart I got an error like this, it was obvious that some object was already disposed but I had made sure (or at least I thought) that I had all the memory disposal issues under control.
After commenting various functions I had targeted the error to a code region like this:
using (FullTextSqlQuery query = new FullTextSqlQuery(SPContext.Current.Site))
{ … }
And after looking in msdn there was a community comment that said:
“You need to be very careful about what SPSite object you pass to this constructor. If you pass in the SPContext.Current.Site
object and you later call the Dispose() method on your instance of the FullTextSqlQuery object (or if you've wrapped the instance in a using statement), you can potentially get the dreaded "Trying to use and SPWeb object that has been closed or disposed ..." error later in the page request. That's because the FullTextSqlQuery class keeps a reference of the SPSite object instance passed into the constructor and when this FullTextSqlQuery instance is disposed, the SPSite object is also disposed”
So the code (for now will be):
Guid idSitio = SPContext.Current.Site.ID;
using (SPSite sitio = new SPSite(idSitio))
{
using (FullTextSqlQuery query = new FullTextSqlQuery(sitio))
{ … }
}
Thanks to Bart X Tubalinal ;)