开发者

how to you code a AvoidCallingProblematicMethods exception to be picked up in FxCop?

开发者 https://www.devze.com 2023-02-03 12:54 出处:网络
I am testing FxCop automation and want to validate it is screening and catching certain rules. I want to make a dll that will trigger the AvoidCallingProblematicMethods error in FxCop.

I am testing FxCop automation and want to validate it is screening and catching certain rules. I want to make a dll that will trigger the AvoidCallingProblematicMethods error in FxCop.

I 开发者_Python百科have the following code but it is not triggering the AvoidCallingProblematicMethods rule at all. what am i doing wrong?

// use one of the listed unsafe methods to create a problematic method
// http://msdn.microsoft.com/en-us/library/bb385973.aspx for list of offending methods
GC.Collect();

how can i trip this FxCop Rule?


Did you analyze not with Visual Studio Code Analysis, but with the stand-alone FxCop?

If so, your code isn't checked because FxCop doesn't support the AvoidCallingProblematicMethods rule.

To be more exact, FxCop doesn't contain Reliability and Maintainability rules. The AvoidCallingProblematicMethods rule is categorized as a Reliability rule.

You can see a comparison table of code analysis rules supported by VS Code Analysis and FxCop from here.

UPDATE

As you will see in Pedro's comment, you can use this rule in FxCop, if you copy VS2010 code analysis rules to FxCop Rules directory.

  1. Backup assemblies in FxCop Rules directory ("%PROGRAMFILES%\Microsoft FxCop 10.0\Rules" by default).
  2. Copy assemblies in "%PROGRAMFILES%\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\Rules" to FxCop Rules directory, except DataflowRules.dll (FxCop can't load rules from DataflowRules.dll).
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号