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

青春壹個敷衍的年華 提交于 2019-12-24 07:36:32

问题


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 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?


回答1:


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).


来源:https://stackoverflow.com/questions/4662211/how-to-you-code-a-avoidcallingproblematicmethods-exception-to-be-picked-up-in-fx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!