roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Analyzer warnings disappear from Error List when the file with the warning is opened

Open svick opened this issue 6 years ago • 16 comments

Version Used: VS 15.8.0 Preview 1.1, .Net Core SDK 2.1.4

Steps to Reproduce:

  1. dotnet new classlib

  2. dotnet add package Microsoft.CodeQuality.Analyzers

  3. Change code in Class1.cs to:

    namespace Foo
    {
        public interface IFoo { }
    }
    
  4. Open the csproj in VS.

  5. Build Solution.

  6. Open Class1.cs.

  7. Wait a few seconds.

Expected Behavior: Whether the analyzer warning "CA1040 Avoid empty interfaces" appears in the Error List should not depend on whether the relevant file is open.

Actual Behavior: When I Build Solution, the analyzer warning "CA1040 Avoid empty interfaces" appears in the Error List. When I open the relevant file, the warning disappears from the Error List after few seconds.

This only happens in the Build + IntelliSense mode. In the Build Only mode, the warning is always visible


I'm assuming this is a general issue. If it's actually an issue with the specific analyzer, I can move this issue to the dotnet/roslyn-analyzers repo.

svick avatar May 12 '18 14:05 svick

Hm, this sounds familiar...I saw similar behavior running static analysis while having the error list set to "Build & Intellisense". As soon as I selected a message/warning/error in the list that caused a new file to open, it would re-populate the error list with Intellisense messages there were already there from the build, ultimately changing the order making it impossible to go thru them from top to bottom. The only way around this was switching the error list to "Build only" then performing the analysis and fixing things with it off.

BhaaLseN avatar May 12 '18 21:05 BhaaLseN

I can confirm this using Visual Studio 15.9.2 and Microsoft .NET core 2.1.5.00 (x64). In our team and repo, this can make people push commits that fail the build on the buildserver, which is of course not good. Is there any hope for progress on this?

HermannGruber avatar Nov 27 '18 15:11 HermannGruber

I confirm this behaviour on 15.9.7. It only appears to happen with one of our analysers (PumaScan).

The behaviour is as described above:

  • Start with all files closed.
  • Build solution.
  • The violation shows in the error list. Double click to open the file.
  • The error disappears from the error list.

If I change the dropdown to "Build Only" it re-appears. Switching back to "Build + IntelliSense" it disappears again.

brettpostin avatar Mar 04 '19 13:03 brettpostin

I can also confirm this still happening with Visual Studio 16.4.3 and .NET Core 3.1, and in my case it has been some (but not all) warnings from FxCop analyzers.

FWIW, the specific warnings that I've noticed disappearing when the corresponding file is opened are CA1008, CA1027, and CA1813. A warning in the same file/class that does not disappear is CA1018. It might also be worth noting that in addition to not listing these warnings in the Error List, there doesn't appear to be any visual indication of any problems in the IDE (ex. nothing with "squiggle underlines", no colors in the scrollbar, etc.).

As others have stated, switching from "Build + IntelliSense" to "Build Only" will bring the "missing" warnings back, and switching back to "Build + IntelliSense" will make them disappear again. This specific problem is covered in issue #19693.

aaron-kruse avatar Jan 20 '20 18:01 aaron-kruse

Reproduction of Issue

Reproduced:

  • Create an analyser (DiagnosticAnalyzer only, do not include an associated CodeFixProvider)
  • Customize it to address a unique issue
  • Add the analyser to a project that triggers the Diagnostic. When the section comes into view, the error/warning/message disappears from IntelliSense.

Resolved:

Add an associated CodeFixProvider handle to the DiagnosticAnalyzer.

Theory

I'm not too aware of Roslyn and IntelliSense from a systems PoV, but it seems to me that if IntelliSense does not identify a solution it can suggest, it will suppress the error/warning/message. This would explain why when you're not using IntelliSense (e.g. CLI compiling, "Show issues generated" is "Build Only") it shows up, but disappears when you try to incorporate IntelliSense.

If this is all true, then I think we should consider moving this issue over to IntelliSense, unless I.S. get's it's queues from Roslyn (again, I don't claim to understand the core of the technologies).

ElectricErger avatar Sep 01 '20 20:09 ElectricErger

For the specific case where a diagnostic is reported by a Compilation End analyzer and Full Solution Analysis is disabled, I'm not sure what the current expected behavior is. For other cases, this issue should be fixed by 16.8 Preview 3.

/cc @mavasani for FSA expectations

sharwell avatar Sep 01 '20 21:09 sharwell

For the specific case where a diagnostic is reported by a Compilation End analyzer and Full Solution Analysis is disabled, I'm not sure what the current expected behavior is.

Compilation end actions for analyzers are executed only if Full solution analysis is enabled. So, in the default VS mode (Full solution analysis is disabled), these compilation end actions are never executed in live analysis. These are essentially build only diagnostics.

mavasani avatar Sep 02 '20 01:09 mavasani

@mavasani it's also possible to trigger the Compilation End actions via the Run Code Analysis command in Solution Explorer

sharwell avatar Sep 02 '20 06:09 sharwell

Unfortunately still happening in VS 2022, making it very impractical to do "one-off" code analyses: Analyze menu > Run Code Analysis > On Solution Microsoft Visual Studio Community 2022, Version 17.3.6, VisualStudio.17.Release/17.3.6+32929.385

equin0x80 avatar Oct 18 '22 15:10 equin0x80

Unfortunately still happening in VS 2022, making it very impractical to do "one-off" code analyses: Analyze menu > Run Code Analysis > On Solution Microsoft Visual Studio Community 2022, Version 17.3.6, VisualStudio.17.Release/17.3.6+32929.385

yep, I came here searching about the same error, VS Community 2022 17.3.6

rolivares avatar Nov 08 '22 12:11 rolivares

Visual Studio 2022 17.4.2 same issue. Run Code Analysis on Project or Solution and issues listed.

Providing you leave as is the list remains but double click an item to fix, file opens and after a few seconds all items disappear (no modifications made to any files).

kiwiant avatar Dec 08 '22 08:12 kiwiant

Any update on this? I was running Code Analysis on my project in VS 17.4.2, but every time I click on a message the list disappears, I thought was my issue and I was going crazy, but looks like it's a long-lasting issue... it's useless to run Code Analysis like this :(

Panda-Sharp avatar Dec 12 '22 10:12 Panda-Sharp

@kiwiant @Panda-Sharp Are you able to provide a simple repro for the issues you are seeing? I just ran Run Code Analysis command on projects within Roslyn.sln, and am able to double click on the reported messages and they still hang around on opening the file. They momentarily disappear as we retrigger code analysis in background whenever a new file becomes active file, but they should immediately be populated with the previously reported (and still active) violations. I am thinking that live analysis is likely busted for your scenarios where the error list clearing part happens on opening the file but live analysis is taking too long to re-analyze and report back the violations for activated file. A repro project or a small gif/demo showing the behavior would certainly help here.

mavasani avatar Dec 13 '22 07:12 mavasani

Alright - I can at least repro one bug: Making any edit in the active file clears out all the code analysis violations reported from prior Run Code Analysis execution. I am going to work on a fix.

mavasani avatar Dec 13 '22 07:12 mavasani

@mavasani Thank you for your reply, here you'll can find everything you need, if you need some more details feel free to ask, thanks!

https://github.com/Panda-Sharp/analyzer-repro

Panda-Sharp avatar Dec 13 '22 09:12 Panda-Sharp

Thanks! I have a PR out with the fix: https://github.com/dotnet/roslyn/pull/66010

mavasani avatar Dec 14 '22 12:12 mavasani

Hi, the problem still exists in VS 2022 Version 17.5.3 when using the analyzer sonar https://marketplace.visualstudio.com/items?itemName=SonarSource.SonarLintforVisualStudio2022

alexeygritsenko avatar Jun 22 '23 18:06 alexeygritsenko

Just updated to Visual Studio Pro Version 17.7.3 and this issue seems to be persisting.

As soon as I start clicking on warnings, I'm looking for 'C++ Core Guidelines' type issues today, the list of intellisense warnings starts whittling itself away until 2200 warning items have vanished before I've fixed a single one.

Since running code-analysis "on a single project", which actually causes it to run on several including the primary library in the solution, took > 14 minutes on a Xeon based workstation, the erratic behavior of the warnings disappearing in the error-list makes this feature unusable.

Was the merged fix included in 17.7.3?

Sand2Silicon avatar Sep 01 '23 17:09 Sand2Silicon

Just updated to Visual Studio Pro Version 17.7.3 and this issue seems to be persisting.

As soon as I start clicking on warnings, I'm looking for 'C++ Core Guidelines' type issues today, the list of intellisense warnings starts whittling itself away until 2200 warning items have vanished before I've fixed a single one.

Since running code-analysis "on a single project", which actually causes it to run on several including the primary library in the solution, took > 14 minutes on a Xeon based workstation, the erratic behavior of the warnings disappearing in the error-list makes this feature unusable.

Was the merged fix included in 17.7.3?

I think I noticed the same last day, but I was not 100% sure, now I'm... with C#

Panda-Sharp avatar Sep 01 '23 18:09 Panda-Sharp

@Sand2Silicon This issue only relates to managed code analysis (C# and Visual Basic). For C++ analysis, you would need to file feedback with the Report a Problem tool in Visual Studio.

sharwell avatar Sep 01 '23 19:09 sharwell

I'm also experiencing this still - Visual Studio 17.10.5.

DanielRouxSA avatar Jul 31 '24 11:07 DanielRouxSA