6

I have created a couple of diagnostic analyzer and code fixes. They all work in the experimental hive as expected.

I build them as a Nuget package and add to a project in a normal instance of VS2015. Oddly one of the analyzer/code-fix combo works correctly, but for the other one only the analyzer works and no code-fixes are suggested (as mentioned it does work in the experimental hive).

My question is, how can I analyze this problem? There's nothing in ActivityLog.xml. Has anyone else observed this behaviour?

UPDATE: I tested using the vsix VS extension in a normal instance and the code fix appeared correctly. I closed that file and re-opened and the code fix was no longer available. No matter how many times I close and re-open the file, the code fix does not come back. But then I open another file that contains a different diagnostic and code fix, and this somehow kick-starts the other code fix, because I can reliably get the code fix back by doing this!

This might sound ridiculous, but I think I've observed this with other 3rd party analyzers. Perhaps there's an issue with my VS install?

Cathal
  • 123
  • 8
  • Roslyn source code is [on GitHub](https://github.com/dotnet/roslyn). The analyzers need to be triggered from there somehow (presumably it's the [AnalyzerDriver](https://github.com/dotnet/roslyn/blob/a4e375b95953e471660e9686a46893c97db70b0e/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs). You could [debug Roslyn](https://github.com/dotnet/roslyn/wiki/Building-Testing-and-Debugging) anlongside your analyzers to see why it does not work. – Stefan Hanke Mar 17 '16 at 04:31
  • I am seeing the exact same thing on VS 2017 RTM on the default code analyzer project, which checks for lowercase in type symbols. The code fix sometimes works, sometimes not. It shows the code fix lightbulb, but when I click it, it just disappears instead of showing the list of code fixes. Tried running both F5 (VSIX) and by installing the nuget it creates. I have not yet found a reliable way to fix this behavior and seems like a bug in Roslyn or possibly Visual Studio. – angularsen Mar 13 '17 at 22:27
  • Wasn't the code fix by any change refactoring? That can be shipped only by Vsix. – Divisadero Jan 02 '20 at 20:09

1 Answers1

0

I faced similar awkward problem when I developed a Nuget package for Roslyn analyzers and code fix providers. When I updated the code and installed the package to the projects, the old package was running instead of the new one. When I closed and reopened Visual Studio, new Nuget package was running.

I am not sure but I guess there is a cache mechanism for Nuget packages in Visual Studio. I didn't try the below method but it may help to resolve your problem.

How to clear NuGet package cache using command line?

Community
  • 1
  • 1
Görkem Özer
  • 504
  • 5
  • 13