C
C#6mo ago
Anton

✅ How come this gives me no warning in Rider?

var f = File.Open("FDJLK", FileMode.Append);
var f = File.Open("FDJLK", FileMode.Append);
For context, I have this in MSBuild
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisLevel>preview</AnalysisLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisLevel>preview</AnalysisLevel>
And this in .editorconfig
dotnet_diagnostic.CA1001.severity = error
dotnet_diagnostic.CA1816.severity = error
dotnet_diagnostic.CA1001.severity = error
dotnet_diagnostic.CA1816.severity = error
What else do I have to do to make it work?
23 Replies
Anton
AntonOP6mo ago
Unused variables also don't count as errors. Why does that happen, even with AnalysisLevel preview
canton7
canton76mo ago
What makes you think that you should get a diagnostic there? Neither CA1001 or CA1816 should fire there
Anton
AntonOP6mo ago
No the code I sent should trigger an IDisposable warning
canton7
canton76mo ago
(Note that it's no longer recommended to implement a finalizer in your IDisposable types in almost all cases, and so SuppressFinalize is irrelevant)
Anton
AntonOP6mo ago
Unused variables is a different issue Just related
canton7
canton76mo ago
What makes you think so? CA1001 isn't relevant to that code "own" means the IDisposable member is a field
canton7
canton76mo ago
No description
Anton
AntonOP6mo ago
Ah shit you're right
canton7
canton76mo ago
And it's about implementing IDisposable, not about calling Dispose on variables/fields
Anton
AntonOP6mo ago
Still ignored
canton7
canton76mo ago
Maybe because it's a Stream?
No description
Anton
AntonOP6mo ago
No I tested it on a custom type
ACiDCA7
ACiDCA76mo ago
i dont know about preview but try to set AnalysisLevel to all as in the docs mentioned its not enabled by default...
Anton
AntonOP6mo ago
There's no such thing
canton7
canton76mo ago
Wut?
Anton
AntonOP6mo ago
C:\Program Files\dotnet\sdk\8.0.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.Analyzers.targets(69,18): error MSB4184: The expres sion "[MSBuild]::VersionGreaterThanOrEquals(all, 5.0)" cannot be evaluated. Version string was not in a correct format.
ACiDCA7
ACiDCA76mo ago
mom
canton7
canton76mo ago
Ah yeah, you're thinking of AnalysisMode
canton7
canton76mo ago
Anton
AntonOP6mo ago
Oh yeah that produced a pile of warnings nice But still none in the ide
canton7
canton76mo ago
Re-run analysis?
ACiDCA7
ACiDCA76mo ago
btw its not enabled by default for a reason.. you are gonna catch quite a few false positives

Did you find this page helpful?