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
0
votes
1 answer

.net6 System.Collections.Immutable clashing with nuget dependencies?

I am writing a Roslyn Analyzer project for .net6.0 and migrating this from a .netstandard2.0 project of the same purpose. It seems the latest Microsoft.CodeAnalysis NuGet dependency (a requirement for Analyzers) requires System.Collections.Immutable…
Cyassin
  • 1,437
  • 1
  • 15
  • 31
0
votes
1 answer

Can I Make Builds Break Based on ReSharper Rules in EditorConfig?

Lately I have tried to get all quality and style rules for my team into an .editorconfig file. As ReSharper still has a larger scope of style rules than .NET Analyzers and other such things, and as it has grown to embrace the EditorConfig approach,…
0
votes
0 answers

.NET 6 SDK on Docker container not loading full namespaces of external packages of projects that target smaller SDKs in Workspace API of Roslyn

I am using .NET 6.0 SDK to register an instance via MSBuildLocator in Roslyn. According to MSBuildLocator.IsRegistered the instance is registered and returns true. Locally everything works perfect and when I load external projects (that target .NET…
0
votes
0 answers

search analyzer and formatter for Visual studio code

I would like to find a linter to analyze the formatting of my code, and also use the linter locally to format my code. And I would want to be able to do that with Visual studio code (and ideally, also Visual studio). Right now, I am using Visual…
Zul Huky
  • 331
  • 4
  • 24
0
votes
0 answers

How to get the details of all the attributes corresponding to a method using Roslyn?

I've been experimenting with Roslyn for 2-3 days now and am unable to figure a couple of things out. I want to extract attribute details of all the methods that have atleast one corresponding attribute. Moreover, I want to seggregate the attributes…
0
votes
0 answers

Understanding code analysis rules and "options"

I'm looking at this rule in particular: 'var' preferences (IDE0007 and IDE0008), which is "enabled" in .editorconfig like so: dotnet_diagnostic.IDE0007.severity = warning The documentation also mentions a number of "options", which look like this…
0
votes
0 answers

how to get symbol for syntax when there is overloading

I'm writing a Roslyn code analyzer to warn when a synchronous version of a method is used and there is an asynchronous version available. I'm going to use it in the context of an ASP.NET Core MVC app which uses EF Core - making synchronous calls to…
ghosttie
  • 588
  • 2
  • 8
  • 18
0
votes
1 answer

NSubstitute analyzer giving a warning incorrectly?

While using the NuGet NSubstitute 4.3.0 and NSubstitute.Analyzers.CSharp, I am trying to intercept a call as follows. _someMock = Substitute.For(); _someMock.ReceivedWithAnyArgs().ExtensionMethod(default); Here actual names are changed…
Codor
  • 17,447
  • 9
  • 29
  • 56
0
votes
0 answers

Calls to DataFlowAnalysis stop Roslyn Analyzer running

I'm trying to write an analyzer that does the following: Find all static field declarations If there are any present, check if there is a function with RuntimeInitializeOnLoadMethod attribute. If there is not, raise a diagnostic If present, check…
0
votes
2 answers

Suppress warning on Rider when attribute is being used - C#

I have a private field in a class that is not assigned anywhere explicitly, its value is actually set using reflections and an attribute that goes on the field. Now, Rider, the IDE I use, warns that the field is never assigned. This warning is what…
0
votes
1 answer

How to force line character length width in a .Net project

In the project I am working on, I am tasked with forcing line character width to 140 characters for a line of code in the visual studio editor. Unfortunately, to my research, any roslyn based analyzer does not support this feature. Can you please…
bugrasitemkar
  • 431
  • 1
  • 7
  • 26
0
votes
0 answers

Roslyn analyser - check for null references for a specific type

I am checking for the possibility to build custom roslyn analyzer for case specifics to our system. The solution is in .net Framework 4.8. I started with the tutorial How to write csharp analyzer code fix and am making my way from there. The first…
Johnny5
  • 6,664
  • 3
  • 45
  • 78
0
votes
1 answer

How can I compare a ClassDeclarationSyntax object against an IdentifierNameSyntax object?

I'm writing a source generator in C#, and I've got 2 objects that I need to compare to see if they relate to the same class, but I can't find a way to do it. My first object is an instance of ClassDeclarationSyntax. This is coming from my custom…
Jamie Burns
  • 1,258
  • 9
  • 21
0
votes
0 answers

How to find the path of a base class via Roslyn?

I am trying to find the path of the base class via Roslyn but I could not find any helpful resource. Does anyone have an idea how to approach the problem. E.g. path: "../File1.cs" contains: using ...; namespace Extraction { class Class1 : Class2…
ce8
  • 23
  • 1
  • 3
0
votes
0 answers

Cannot access included files SourceGenerator

I added this ItemGroup to the SourceGenerator.csproj file
Mário Gabriel
  • 367
  • 1
  • 2
  • 13