Roslyn-analyzers: CA2000 - False positives

Created on 24 Nov 2017  路  10Comments  路  Source: dotnet/roslyn-analyzers

Analyzer package

Microsoft.CodeQuality.Analyzers

Analyzer

CA2000: Dispose Objects Before Losing Scope

Repro steps

  1. Follow https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2000-dispose-objects-before-losing-scope for example good code
    2a) Allow IDE0017 to be applied - Object initialization can be simplified - on the temporary object
    or
    2b) Add a catch statement
    or
    2c) Encapsulate the return object (unsure if this is a false positive or a real positive

Expected behavior

CA2000 not to be reported

Actual behavior

CA2000 is reported

Sample code file attached.
CA2000.txt

Since i think it is 2 (potentially 3) false positives, but all on the same rule, i didn't know if you would want me to report them grouped together, or as a separate report for each. Sorry if i shouldn't have grouped them.

thanks
Mike

(And thanks for Roslyn and the Analyzers - they are great :))

Bug DataFlow False_Positive Urgency-Soon

Most helpful comment

All 10 comments

@MrMikeJJ Can you please tell us the version of the analyzer package and VS version you are using?

Hi Mavasani,
Certainly :)
I am using Visual Studio Professional 2017 - Version 15.4.4
This is found using the analyzer built into Visual Studio, under "Run Code Analysis on Solution".
According to the output window, this is C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe
That program reports itself as
Microsoft (R) FxCop Command-Line Tool, Version 15.0 (15.0.26906.1) X86
If that is what you were after ?
thanks
Mike

Was this page helpful?
0 / 5 - 0 ratings