Questions tagged [roslyn-code-analysis]

For questions regarding code analysis for C# and VB based on the Roslyn .NET compiler platform API.

The Roslyn compiler platform provides an API to implement code analysis, code fixes, and refactoring tools for C# and VB.

The Roslyn Wiki also contains an introduction for "How To Write a C# Analyzer and Code Fix" and for Visual Basic.

769 questions
8
votes
1 answer

Roslyn source generator is "ignored"?

I'm creating a simple Roslyn Source Generator. The generator seems to work well in debug, correctly generating the desired class. However, when referencing it from another project in the solution, a red icon is shown near it with the "Ignored"…
Impworks
  • 2,647
  • 3
  • 25
  • 53
8
votes
1 answer

Can I force a non-exhaustive c# switch expression to cause a compile error?

I like switch expressions for mapping enums to values - while not the most scalable solution, it's fast and fairly clean if the enum represents something modal (and isn't huge). One often source of bugs is adding members to an enum - which often…
Jonathan Levin
  • 594
  • 3
  • 13
8
votes
1 answer

How can I make a Roslyn Analyzer project a transitive dependency?

I have a library that relies on a source generator to work correctly. In the MyLibrary.csproj, I reference the generator like so.
chyyran
  • 2,446
  • 2
  • 21
  • 35
8
votes
0 answers

Roslyn - SyntaxNode "disappears" if Trailing trivia is added

I'm working on a little piece of roslyn code to try to do some simple refactorings, inside a Visual Studio for MAC extension project. I want to refactor this code: public class Test { private const object a = null; public const int c =…
Miiite
  • 1,517
  • 10
  • 16
8
votes
3 answers

C# Roslyn Compiler - How to get namespace of a type from IdentifierNameSyntax?

Suppose I have a call in the code, SomeClass.SomeStaticMethod(), which is an InvocationExpressionSyntax. I get name of the generic type T as string (from IdentifierNameSyntax). I tried to get Symbol of T but I did not succeed. How can I find out…
Görkem Özer
  • 504
  • 5
  • 13
8
votes
2 answers

Roslyn - Is symbol implementation of interface?

Is it possible to know with Roslyn if a Symbol is the implementation of something in an interface? For example Dispose() in IDisposable? I have a symbol that represents the Dispose() method, but as far as I can see there is no property that…
TWT
  • 2,511
  • 1
  • 23
  • 37
8
votes
1 answer

Reliably compare type symbols (ITypeSymbol) with Roslyn

I am trying to reliably compare two instances of ITypeSymbol the easiest and most straight forward way possible in the following situation (I came across these issues in a bigger project and tried to simplify it as much as possible): I have got a…
Alex
  • 569
  • 5
  • 21
7
votes
2 answers

C# Source Generator not including results from Project Reference

Edit3: At some point this just started working. No clue why. Maybe it was a VS bug that got fixed? Edit2: Looking into the Analyzers node in solution explorer, I've discovered the source generator runs successfully when I first open the program, and…
7
votes
1 answer

Unable to add native .dll reference to source generator project

You can find the full source code at https://github.com/myblindy/GrimBuilding/tree/efcore (the efcore branch). I understand that source generators can't automatically harvest dependencies from nuget packages and you have to use a clunky work-around…
Blindy
  • 65,249
  • 10
  • 91
  • 131
7
votes
2 answers

c# Roslyn get IParameterSymbol from ArgumentSyntax

I have an ArgumentSyntax in some invocation expression, how can I get corresponding IParameterSymbol in the IMethodSymbol of the invocation? Since I have seen ArgumentSyntax.NameColonSyntax, which means the argument might have some name, I cannot…
Xiaoyou Zhai
  • 103
  • 6
7
votes
1 answer

CA1801 vs IDE0060

In VS 2019, unused parameters are now showing two issues in the "Error List" instead on one: CA1801, which appears as a warning, and IDE0060, which appears as a suggestion. Do these analysis rules do the same thing? If not, how are they different.…
Dan Friedman
  • 4,941
  • 2
  • 41
  • 65
7
votes
1 answer

MSBuildWorkspace cannot compile project with to another project

Note I've also asked this question (with reproduction code) on Roslyn's GitHub Create a new solution with 2 projects (CoreLibrary and DownstreamLibrary). Add a project reference from DownstreamLibrary to CoreLibrary. Run the following code and note…
RB.
  • 36,301
  • 12
  • 91
  • 131
7
votes
4 answers

Constant build failure (Roslyn/CodeAnalysis) since Visual Studio 2017 version 15.8. Any ideas?

Since Visual Studio 2017 version 15.8 we have on some computers in my team the following really weird build error. Additionally Visual Studio recognizes it but the IDE itself doesn't crash. To check if it only happens to our own solutions I…
Mil
  • 756
  • 2
  • 11
  • 30
7
votes
2 answers

Resolve NuGet Version Conflict

I'm trying to install an update through NuGet: Microsoft.AspNetCore.Mvc 1.1.2 --> 2.0.4 However, the update never succeeds as it is rolled back after encountering the following conflict: Version conflict detected for Microsoft.CodeAnalysis.CSharp.…
Force444
  • 3,321
  • 9
  • 39
  • 77
7
votes
1 answer

What's the correct way to deliver dependencies for Roslyn analyzers?

We have started to include Roslyn analyzers with some of our libraries to make the features of those libraries more discoverable by our developers. To facilitate this we have a shared library that the analyzers use. So we have the shared component, …
Sam Holder
  • 32,535
  • 13
  • 101
  • 181
1 2
3
51 52