New FxCop Rule Requested

Folks:

My I recommend the addition of a new rule (or does this rule already exist ).

FxCop should generate a warning message when an object that implements the IDisposable interface is instantiated in a method, and is only used in that method, and is not part of a using block, and isn't disposed.

Sincerely,

Eric Bergman-Terrell
www.PersonalMicroCosms.com


Answer this question

New FxCop Rule Requested

  • VasuK

    Hi James,

    I would love to receive the code now if you don't mind. I will use it until MS ships the new rules. I have currently no time to create it myself.

    Thanks,

    Fons


  • Bryce Eddings

    This rule does exist but we neglected to ship it in the last update to FxCop. This was an oversight. I'll talk to the team about a timeframe for correcting this issue and will post another reply here soon.

    Michael

  • CSomercik

    It's not too tricky to write this rule yourself. I wrote one for internal use, but it's rather messy as it walks the IL to identify compilation patterns, as the VisitMethod etc calls hadn't been talked about on here when I wrote the rule. A bit of time with ILDASM and some source code and you can figure out the patterns.

    I would post the source, but as I said it's rather messy (rule has 3 level inheritence - our generic base class that sets the rule XML location etc, a class on top of that which contains methods for identifying using constructs in IL (you need to keep track of certain locals / stack positions) and the the rule on top).

    Or you could wait until they publish this rule ;)

  • hoabinh

    Hi Michael,

    Are you planning to publish this extra rule soon

    Thanks,

    Fons


  • ghenap

    I think that alone would be more helpful than all the other rules put together. (Though the rest of the rules are still really useful.)

    Jonathan


  • PeterSanDiego

    This rule won't make it in the RTM of FxCop 1.35, however, it will be shipped in the next version after that.

    We are in the process of rewritting our dataflow analysis, so basically any rule that touches a method body (ie Method.Instructions), including this one, will be rewritten along with it.



  • New FxCop Rule Requested