Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION)) in SharePoint
        Posted  
        
            by BeraCim
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by BeraCim
        
        
        
        Published on 2010-04-12T05:44:21Z
        Indexed on 
            2010/04/12
            5:53 UTC
        
        
        Read the original article
        Hit count: 1191
        
sharepoint
|sharepoint2007
Hi all:
After googling for many hours for a solution for the above Sharepoint exception, I have come to SO for help on this one...
I believe the cause of me getting the above exception is because of the following code:
try
{
    using (SPSite site = new SPSite(siteId, spUserToken))
    {
        using (SPWeb web = site.OpenWeb(webId))
        {
            createNewSite(web);
        }
    }
}
createNewSite(web) changes the name and URL of "web" using AllowUnsafeUpdates, so when it comes out of the method it has been changed. My few months worth of Sharepoint developing experience suggest that that is the cause of the exception. "web" is no longer used anymore so I can comfortably null it myself. The problem here is... it didnt work:
try
{
    using (SPSite site = new SPSite(siteId, spUserToken))
    {
        SPWeb web = null;
        using (web = site.OpenWeb(webId))
        {
            createNewSite(web);
            if (web != null)
            {
                web = null;
            }
        }
    }
}
I believe that the original developer used the using declaration to avoid SPWeb objects from leaking. Asides that I think it is okay for me to break this pattern solely for the purpose of getting rid of that dreaded exception.
So the question: what can I do to the above code to potentially fix this exception?
Thanks.
© Stack Overflow or respective owner