开发者

FxCop CA2000 Warning in UserControls

Running FxCop on a WebProject that contains a UserControl will result in a CA2000 Warning (Call System.IDisposable.Dispose on object) for every ServerControl (Label, TextBox,...) in that UserCon开发者_JAVA百科trol.

I understand why this would happen.

Replacing the 'offending' ServerControls with a PlaceHolder and then adding the Controls in code (Using...End Using) might be a way around that, but it is not always an option.

But, if they are not 'kosher' why have ServerControls you can drop in your ascx/aspx in the first place ?

Am I missing something ?

If, like in my case, you inherit a sizeable collection of fairly complex UserControls, do I now add every 'offending' Control to the GlobalSupperssions file (that's a lot of mind numbing right-clicking) ?

I do not want to suppress all CA2000 warnings since it makes perfect sense to fix them, but not in the case of ServerControls in UserControls.


Hmya, everybody really likes a tool that will tell them that they forgot to call Dispose(). Problem is: such a tool is really hard to implement. The specific warning you are talking about got disabled and re-enabled a few times now.

Obviously the warning you got is nonsense, a UserControl already knows how to properly dispose its member controls. It is just not something that an automated tool can easily detect. The dispose call is a million miles removed from the constructor call, buried in .NET framework code with a couple of virtual methods and event handlers thrown in the mix.

To really evaluate those warnings, you'll have to switch to another tool: the one between your ears.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜