在我的 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/