SPWeb处置自己并导致异常

时间:2009-09-21 11:39:39

标签: sharepoint exception dispose

当尝试使用SPWeb.GetSiteData(SPSiteDataQuery)(尝试将某些数据绑定到SPGridView)时,它会抛出一个带有以下堆栈跟踪的TargetInvocationException:

异常

  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)

正在调用的方法是GetData。在使用消息Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))调查InnerException之后,看起来SharePoint想要释放资源:

   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)

但所有这些方法直到SPWeb.Dispose()我都没有在调用SPWeb.GetSiteData(SPSiteDataQuery)之前处置任何内容,然后抛出异常。

我的代码

SPWebApplication的实例我是这样的 - Microsoft.SharePoint.WebControls.SPControl.GetContextWebApplication(HttpContext.Current);

然后我在函数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
         ....
      }
   }
}

有什么想法吗?谢谢。

1 个答案:

答案 0 :(得分:0)

事实证明原因是,对于某些列表,TemplateFeatureId属性设置为一个实际上不存在或以某种方式更改的模板。在我的情况下,我只是重新创建了这些列表,现在查询运行正常。

通过这篇文章找到了这个:http://blog.myitechnology.com/2009/06/fixing-feature-guid-for-list-template.html

只是不要使用该工具来解决问题 - 他说他正在修改内容数据库(我想直接)。那是不禁的。我只是用它来查看哪些列表有问题。