C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Failed to add web part (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION)) exception


Posted Date: 06 Aug 2008    Resource Type: Errors and Solutions    Category: General
Author: Prasham SabadraMember Level: Silver    
Rating: Points: 10



The exception that we try to solve here is : Failed to add web part (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION)) while adding any web part on SharePoint site

The various scenarios in which this may occur are:

1. We have created a SharePoint site using custom site definition and custom page layouts. On home page we have our modified content query web part. Content query web part queries to Pages library on the site. This is the scenario in our case only.

2. You developed a custom web part and obtain SPSite and SPWeb objects from current context.

Problem: We can’t add another web part on that page. Neither out of box nor custom web part. We are only getting the exception
Failed to add webpart (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))

Cause: We have overriding the out of box Content Query web part. In that code we are getting SPSite and SPWeb object from the current context like


using(SPSite site = SPContext.Current.Site)
{
using(SPWeb spWeb = site.OpenWeb(web))
{
//Some code goes here
}
}


So problem lies in above two statements where we are getting SPSite and SPWeb object from the context in the using block. So as soon as this code gets executed these objects get disposed. And current site is root site. So whenever we obtain SPSite and SPWeb object from the context, these objects should not be disposed.

The objects SPSite and SPWeb obtained from the context maintain an internal list that is derived in fashion if we dispose these objects may cause SharePoint behave unpredictably. SharePoint disposes these objects itself.


For more details, visit http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
WebPart addition failed  .  WebPart  .  SharePoint  .  Failed to Add WebPart  .  Custom WebPart  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Error with UpdatePanel control - Solution
Previous Resource: How to avoid Multiple selection not allowed in DropDownList problem
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use