SPDisposeCheck 报告 SiteProvisioning.RestoreDataViewOutZone 方法上的错误
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于弄清楚
http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example。 aspx#SPDisposeCheckID_160
GetLimitedWebPartManager 方法返回应处置的 SPWeb 对象。
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.