Is there an FxCop rule for this? Yes and no.
In FxCop 1.35, which is based on Visual Studio 2005 code analysis, there was a DisposeObjectsBeforeLosingScope rule that did just that.
In FxCop 1.36 (Visual Studio 2008 code analysis), they removed the data flow analysis engine, which meant that this rule also needed to be removed.
However, in the following FxCop code analysis ( Visual Studio 2010 ), it seems that DisposeObjectsBeforeLosingScope is back!
bobbymcr
source share