C# SPDisposeCheck报告SiteProvisioning.RestoreDataViewOutZone方法上的错误
我在我的SharePoint程序集上运行了SPDisposeCheck工具,但它在SiteDefinitionAssembly上报告了三个错误,该程序集也具有站点设置处理程序。据我所知,这段代码是由项目模板本身生成的,我们不应该更改它。我得到的错误是C# SPDisposeCheck报告SiteProvisioning.RestoreDataViewOutZone方法上的错误,c#,sharepoint,wss,C#,Sharepoint,Wss,我在我的SharePoint程序集上运行了SPDisposeCheck工具,但它在SiteDefinitionAssembly上报告了三个错误,该程序集也具有站点设置处理程序。据我所知,这段代码是由项目模板本身生成的,我们不应该更改它。我得到的错误是 ID: SPDisposeCheckID_160 Module: SynergyOnline.NFER.ProjectSiteDefinition.dll Method: ProjectSiteDefinition.SiteProvisioning
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对象,但我不确定是否应该释放它
我需要担心这个错误吗
谢谢你终于明白了
GetLimitedWebPartManager方法返回应释放的SPWeb对象 终于明白了
GetLimitedWebPartManager方法返回应释放的SPWeb对象