views:

128

answers:

1

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

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.

A: 

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.

Hans Passant
Thanks, you pretty much confirm what was between my ear, which I guess is what I needed.
esjr