SPDisposeCheck报告SiteProvisioning.RestoreDataViewOutZone方法上的错误

时间:2009-12-03 20:46:38

标签: c# sharepoint wss

我在SharePoint程序集上运行了SPDisposeCheck工具,但它在SiteDefinitionAssembly上报告了三个错误,它们也有站点配置处理程序。据我所知,这个代码是由项目模板本身生成的,我们不应该改变它。我得到的错误是

ID: SPDisposeCheckID_160
Module: SynergyOnline.NFER.ProjectSiteDefinition.dll
Method: ProjectSiteDefinition.SiteProvisioning.RestoreDataViewInZone(Microsoft.S
harePoint.SPWeb,System.String)
Statement: local6 := local5.{Microsoft.SharePoint.SPFile}GetLimitedWebPartManage
r(1)
Notes: Dispose/Close was not called on SPLimitedWebPartManager.Web
More Information: http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-20
07-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_160
----------------------------------------------------------


ID: SPDisposeCheckID_160
Module: SynergyOnline.NFER.ProjectSiteDefinition.dll
Method: ProjectSiteDefinition.SiteProvisioning.RestoreDataViewOutZone(Microsoft.
SharePoint.SPWeb,System.String)
Statement: local12 := local5.{Microsoft.SharePoint.SPFile}GetLimitedWebPartManag
er(1)
Notes: Dispose/Close was not called on SPLimitedWebPartManager.Web
More Information: http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-20
07-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_160
----------------------------------------------------------


ID: SPDisposeCheckID_160
Module: SynergyOnline.NFER.ProjectSiteDefinition.dll
Method: ProjectSiteDefinition.SiteProvisioning.RestoreDataViewOutZone(Microsoft.
SharePoint.SPWeb,System.String)
Statement: local14 := local11.{Microsoft.SharePoint.SPFile}GetLimitedWebPartMana
ger(1)
Notes: Dispose/Close was not called on SPLimitedWebPartManager.Web
More Information: http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-20
07-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_160
----------------------------------------------------------

以下是gerenrated的代码

private void RestoreDataViewInZone(SPWeb web, string filePath)
        {
            if (!File.Exists(filePath) || web == null)
            {
                return;
            }

            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load(filePath);
            }
            catch (XmlException)
            {
                return;
            }

            XmlNodeList xFixupFiles = doc.DocumentElement.SelectNodes("FixupFiles/FixupFile[@DataViewInZone=\"TRUE\"]");
            foreach (XmlNode xFixupFile in xFixupFiles)
            {
                XmlAttribute xRelativePath = xFixupFile.Attributes["RelativePath"];
                if (xRelativePath == null)
                {
                    continue;
                }
                string relativePath = xRelativePath.Value;

                SPFile file = web.GetFile(relativePath);
                if (file == null)
                {
                    continue;
                }

                SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
                SPLimitedWebPartCollection pageWebParts = manager.WebParts;
                if (pageWebParts == null)
                {
                    continue;
                }

                foreach (System.Web.UI.WebControls.WebParts.WebPart webPart in pageWebParts)
                {
                    DataFormWebPart dataForm = webPart as DataFormWebPart;
                    if (dataForm == null)
                    {
                        continue;
                    }

                    this.SubstituteGuidInZone(web, manager, dataForm, filePath);
                }
            }
        }

我知道SPWeb对象没有放在函数中,但我不确定它是否应该被处理掉。

我是否需要担心此错误?

由于

1 个答案:

答案 0 :(得分:1)