Question

We've recently run into very strange issue: Calling spWeb.Lists.TryGetList("blaBlaBLa"); from DelegateControl code is causing the view containing cross site lookup field to crash.

More details:

We have a root site - SiteA. There is a list ListA there and a site column - lookup field targeting ListA, the column called FieldA.

Also there is a subsite SiteB that has a list ListB. We have added the FieldA to ListB. When browsing the ListB and switching to view containing FieldA the web part crashes.

We found out that crashing happens only when the feature containing custom DelegateControl is activated. So we started removing the code of this control line by line to find what exact line is causing the issue. By the end we have found the target line:

// this code doesn't throw any exception
var a = SPContext.Current.Web.Lists.TryGetList("blaBlaBLa");
// a == null: true

Few notes: blaBlaBla doesn't exist on subsite nor on root site, there is no such list at all. This line doesn't throw any exception. The issue only happens on a subsite. After removing this line the crash is gone.

Here is an exception message from ULS logs:

Error while executing web part: System.ArgumentException: List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user. ---> Microsoft.SharePoint.Client.ResourceNotFoundException: List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user. - -- End of inner exception stack trace --- at Microsoft.SharePoint.SPListCollection.ItemByInternalName(String strInternalName, Boolean bThrowException) at Microsoft.SharePoint.SPListCollection.GetListById(Guid uniqueID, Boolean bThrowException) at Microsoft.SharePoint.SPFieldLookup.get_DispFormUrl() at Microsoft.SharePoint.SPFieldLookup.AnnotateField(XmlNode fieldRefNode) at Microsoft.SharePoint.WebPartPages.XsltListViewWebPart.AddInFieldSchema(XmlNodeList fieldRefNodes, SPList list) at Microsoft.SharePoint.WebPartPages.XsltListViewWebPart.AddInTypeInfoIntoViewXml(XmlNode viewXml) at Microsoft.SharePoint.WebPartPages.XsltListViewWebPart.ModifyXsltArgumentList(ArgumentClassWrapper argList) at Microsoft.SharePoint.WebPartPages.DataFormWebPart.PrepareAndPerformTransform(Boolean bDeferExecuteTransform)

So the code for checking if list exists causing not-related webpart to crash. Any fix, workaround for this issue?

Was it helpful?

Solution

I havent got exact issue but one thing I can say is SharePoint doesn't like when you mess directly with SPContext.Current.Web object. Can you rather try something like below;

   using (SPSite newSite = new SPSite(SPContext.Current.Site.ID))
   {
    using (SPWeb web = newSite.OpenWeb(SPContext.Current.Web.ID))
    {
     var a = web.Lists.TryGetList("blaBlaBLa"); ;
    }
   }

Check for the ID here. Which means we are creating a FRESH SPSite/SPWeb object instead of directly asking SPContext.Current.Web to find the list.

OTHER TIPS

Try

SPContext.Current.Site.Web.Lists.TryGetList("blaBlaBLa");

because, SPContext.Current.Web.Lists.TryGetList("blaBlaBLa"); reach always root site.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top