Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION)) in SharePoint

强颜欢笑 提交于 2020-01-06 15:12:12

问题


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.


回答1:


Having a method called createNewSite that changes an existing site is a bad sign - you should post the code for that also.

There is however no need to set web to null - it doesn't have any effect as it is about to go out of scope anyway.

A more likely cause is something wrong in the custom method you are calling or an issue with the validity of the ids used.



来源:https://stackoverflow.com/questions/2620085/exception-from-hresult-0x80020009-disp-e-exception-in-sharepoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!