asp.net - SPDispose Ignore 属性不忽略

标签 asp.net sharepoint sharepoint-2010

在我的 SharePoint 代码中,我有以下行:

SPWeb web = site.RootWeb;//site是一个SPSite对象

当我重建项目并在程序集上运行 SPDispose 工具时,出现以下错误:

<小时/>

Module: Blah.SharePoint.Features.Core.dll Method: Blah.SharePoint.Features.Core.Helpers.FeatureDeploymentHelper.RemoveWebPartFiles(Microsoft.SharePoint.SPFeatureReceiverProperties,System.String) Statement: web := site.{Microsoft.SharePoint.SPSite}get_RootWeb() Source: C:\xxx\xxx\Main\Source\SharePoint\Features\Core\Helpers\FeatureDeploymentHelper.cs Line: 26

Notes: Disposable type not disposed: Microsoft.SharePoint.SPWeb
***This may be a false positive depending on how the type was created or if it is disposed outside the current scope More Information: http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_140

<小时/>

我想要做的是让 SPDispose 工具忽略此错误,因此我已将 SPDisposeCheckIgnore 类和支持枚举拉入我的项目中,并适本地修饰了我的方法:

[SPDisposeCheckIgnore(SPDisposeCheckID.SPDisposeCheckID_140, "RootWeb does not need disposed.")]

public static void RemoveWebPartFiles(SPFeatureReceiverProperties properties, string assemblyName)
{ 
...
}

完成所有这些操作后,我仍然收到错误。有人知道我该如何消除该错误吗?

最佳答案

这里需要做两件事。

1) SPDisposeCheckIgnore 类必须在 SPDisposeCheck 命名空间中定义。你不能拥有自己的命名空间。参见本页相关评论:http://archive.msdn.microsoft.com/SPDisposeCheck/

2) 您在 RunWithElevatedPrivleges 中尝试忽略的任何内容都必须放入外部方法中,否则将无法被识别。上面的示例中没有执行此操作,但在其他地方执行了此操作。

必须遵循这两条规则才能忽略。希望这对其他人有帮助。

关于asp.net - SPDispose Ignore 属性不忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11434486/

相关文章:

c# - 具有复杂 ItemType 失败的 ASP.NET 强类型数据控件(中继器)

php - PHP 中的 Sharepoint GetListItemChangesSinceToken CURL 请求

c# - 模式对话框 - SharePoint 2010

javascript - ASP.NET 中的多个 Google 图表

javascript - 在某处内联渲染一个 div,而它实际位于其他地方?

.net - 是否为每个请求创建 AppDomains?

c# - "IsDlg=1"是什么意思? - 共享网站

SharePoint 列表 - vLookup 类型功能

sharepoint-2010 - 删除计算列表中的空格

sharepoint - 为什么应用步骤在 SharePoint Designer 中显示为灰色