本文介绍了FxCop 10:CA2122与CA2135冲突/矛盾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更新VS2008的解决方案& FxCop 1.36到VS2010& FxCop 10,以及将项目更新为.Net 4的一部分。 我现在收到一堆CA2135错误,说不应该有LinkDemands,而是应该将方法标记为
as [SecurityCritical]。 好的,我通过SecurityCritical替换LinkDemand属性。 现在我得到CA2122(不要间接地暴露具有链接要求的方法)。

I'm updating a solution from VS2008 & FxCop 1.36 to VS2010 & FxCop 10, and as part of that updating the projects to .Net 4.  I'm now getting a bunch of CA2135 errors saying that there shouldn't be LinkDemands, and instead methods should be marked as [SecurityCritical].  OK, I go through and replace the LinkDemand attributes with SecurityCritical.  Now I get CA2122 (Do not indirectly expose methods with link demands) on every one of those.

除非我遗漏了某些东西,否则似乎不能同时满足这两个规则。

Unless I'm missing something, it seems that one can't satisfy both rules at once.

例如,我正在处理的特定项目是对System.Windows.Threading.Dispatcher.UnhandledExceptionFilter事件的引用。

As an example, the particular item I'm working on right now are references to the System.Windows.Threading.Dispatcher.UnhandledExceptionFilter event.

推荐答案

感谢您的举报!

CA2135可在Visual Studio中使用2010年,我可以问你VS的版本吗?我在我的机器上做了一个简单的测试。不幸的是,这个问题无法再现。我的Visual Studio版本信息是:

CA2135 is avaiable in Visual Studio 2010, can I ask the version of you VS? I did a simple test on my machine. Unfortunately, the issue can not be reproduced. My Visual Studio version info is:

版本10.0.30319.1 RTMRel和.NET Framework版本4.0.30319 RTMRel。

Version 10.0.30319.1 RTMRel and .NET Framework Version 4.0.30319 RTMRel.

如果您愿意,请创建一个新项目并测试以下代码片段:

If you will please create a new project and test the following code snippet:


using System;
using System.Security;
using System.Security.Permissions;

namespace AssemblyTest
{
    public class TestClass
    {
       //[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)]
       [SecurityCritical()]
       public void TestMethod()
       {
          // some work here...
       }
    }
}


这篇关于FxCop 10:CA2122与CA2135冲突/矛盾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 05:22