When trying to use SPWeb.GetSiteData(SPSiteDataQuery)
(Trying to bind some data to SPGridView), it throws me an TargetInvocationException with a following stacktrace:
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance)
at System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)
at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.WebControls.GridView.DataBind()
at Balticovo.SharePoint.WebParts.CrossSiteDataQueryWebPart.OnLoad(EventArgs e)
The method that is being invocated is GetData. After investigating InnerException with message Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
it looks like SharePoint want to release resources somwhere:
at Microsoft.SharePoint.Library.SPRequest.ReleaseResources()
at Microsoft.SharePoint.SPRequestManager.Release(SPRequest request)
at Microsoft.SharePoint.SPWeb.Invalidate()
at Microsoft.SharePoint.SPWeb.Close()
at Microsoft.SharePoint.SPWeb.Dispose()
at Balticovo.SharePoint.Extensions.GetCrossSiteData(SPWebApplication webApp, SPCrossSiteDataQuery query)
at Balticovo.SharePoint.TasksTableAdapter.GetData(Guid queryId, Boolean dataForOutlook)
at Balticovo.SharePoint.TasksTableAdapter.GetData(Guid queryId)
But all those methods up to SPWeb.Dispose() I don't dispose anything before I call SPWeb.GetSiteData(SPSiteDataQuery) which then throws an exception.
Instance of SPWebApplication i get like this - Microsoft.SharePoint.WebControls.SPControl.GetContextWebApplication(HttpContext.Current);
Then i do some stuff like this in function GetCrossSiteData:
foreach (string siteUrl in query.QuerySites)
{
try
{
using (SPSite site = new SPSite(siteUrl))
using (SPWeb web = site.OpenWeb())
{
DataTable dt = web.GetSiteData(query.SiteDataQuery); //Hangs here
....
}
}
}
Any ideas? Thank you.
Turns out that the cause was that for some lists TemplateFeatureId property was set to a template that does not really exist or was changed in some way. As in my case i just recreated those lists and now queries are running fine.
Found this out by this article: http://blog.myitechnology.com/2009/06/fixing-feature-guid-for-list-template.html
Just DO NOT USE that tool to fix the problem - he say's he's modifying the content database (i suppose directly). That's a no-no-no. I just used it to see which lists have the problem.
User contributions licensed under CC BY-SA 3.0