Cannot save the property settings for this Web Part. Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))

Hi all,

I was working with a webpart in MOSS and I created my custom toolpart for configuring the web part. Once, when I was trying to save the settings, I got the error – “Cannot save the property settings for this Web Part. Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))”. I was confused and when I tried to debug the webpart I was not hit by any exceptions.

After crawling through some articles I found that I was disposing the SPWeb and SPSite objects which stores the current context of the site. So I removed all the code disposing the SPWeb and SPSite objects STORING THE CURRENT CONTEXT OF THE SITE (you have to dispose the usual SPSite and SPWeb objects with Using statements or disposing them in the ‘finally’ blocks). And bingo, it worked.

You may also get the following error

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

while trying to add a webpart.

So never dispose those objects when they belong to the current context.

Me