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

发布于 2024-08-13 14:07:43 字数 3722 浏览 2 评论 0原文

我在 SharePoint 程序集上运行了 SPDisposeCheck 工具,但它在 SiteDefinitionAssembly 上报告了三个错误,该 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
----------------------------------------------------------

这是生成的代码

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 对象未在函数中释放,但我不确定是否应该释放它。

我需要担心这个错误吗?

谢谢

I ran the SPDisposeCheck tool on my SharePoint assemblies but it reported three errors on a SiteDefinitionAssembly which also has the site provisioning handler. As far as I understand it this code is generated by the project template itself and we are not supposed to change it. The error I get is

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
----------------------------------------------------------

Here is the code that is 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);
                }
            }
        }

I do know that the SPWeb object is not disposed in the function but I am not sure if it should be disposed or not.

Do I need to worry about this error?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟燃烟灭 2024-08-20 14:07:43

Finally figured it out

http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_160

GetLimitedWebPartManager method returns a SPWeb object which should be disposed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文