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.
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.
User contributions licensed under CC BY-SA 3.0