如何编写一个要在FxCop中获取的RemoveCallsToGCKeepAlive异常?

时间:2022-09-01 07:32:16

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 RemoveCallsToGCKeepAlive error in FxCop.

我正在测试FxCop自动化,希望验证它正在筛选和捕捉某些规则。我想创建一个dll来触发FxCop中的RemoveCallsToGCKeepAlive错误。

I have the following code but it is not triggering the RemoveCallsToGCKeepAlive rule at all. what am i doing wrong?

我有以下代码,但它根本没有触发RemoveCallsToGCKeepAlive规则。我做错了什么?

static void Gen_RemoveCallsToGCKeepAlive(){
    string str = "";
    GC.KeepAlive (str);
}

how can i trip this FxCop Rule?

我怎么能违反FxCop规则呢?

1 个解决方案

#1


1  

If you use the stand-alone FxCop, your code isn't checked for the same reason of this.

如果您使用独立的FxCop,您的代码不会因为同样的原因而被检查。

The RemoveCallsToGCKeepAlive is a Relialibity rule so FxCop doesn't support it.

RemoveCallsToGCKeepAlive是一个可靠性规则,所以FxCop不支持它。

UPDATE

更新

You can use this rule in FxCop, if you copy VS2010 code analysis rules to FxCop Rules directory. For more detail, refer to my answer of this question.

如果将VS2010代码分析规则复制到FxCop规则目录,则可以在FxCop中使用该规则。要了解更多细节,请参考我对这个问题的回答。

#1


1  

If you use the stand-alone FxCop, your code isn't checked for the same reason of this.

如果您使用独立的FxCop,您的代码不会因为同样的原因而被检查。

The RemoveCallsToGCKeepAlive is a Relialibity rule so FxCop doesn't support it.

RemoveCallsToGCKeepAlive是一个可靠性规则,所以FxCop不支持它。

UPDATE

更新

You can use this rule in FxCop, if you copy VS2010 code analysis rules to FxCop Rules directory. For more detail, refer to my answer of this question.

如果将VS2010代码分析规则复制到FxCop规则目录,则可以在FxCop中使用该规则。要了解更多细节,请参考我对这个问题的回答。