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
44
votes
3 answers

VS 2022: High RAM and CPU issue with Roslyn Code Analysis

We have a huge solution (ASP.NET MVC, C#) in Visual Studio 2022 (v.17.2.2 64bit). Roslyn Code Analysis is always using high CPU and RAM. Is there a way to prevent this issue? A configuration or something else?
kiafiore
  • 1,071
  • 2
  • 11
  • 27
35
votes
2 answers

Enabling Microsoft's Code Analysis on .NET Core Projects

Our team uses the Code Analysis feature with a custom ruleset to cause our build to fail if we forget to do things like null checks on method arguments. However, now as we create a new .NET Core project, it doesn't look like Code Analysis is a…
StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
30
votes
5 answers

VS Project References Broken On Case Sensitivity of GUID

Since upgrading to VS 2015, my team has experienced random quirky things which I'm sure are being worked out at Microsoft right now. One pretty annoying one is that we seem to lose project references, especially after branching. I began to work on…
23
votes
3 answers

Confused over ruleset files vs. EditorConfig files

Our organisation uses a ruleset file containing our organisation's StyleCop.Analyzers settings. This lives in source control, and all projects in all solutions in our organisation reference this file. If I edit the ruleset (via project properties →…
23
votes
7 answers

CSharpAddImportCodeFixProvider encountered an error and has been disabled

I had my PC re-imaged for me. I have Visual Studio Version 14.0.25123.00 Update 2 installed on my computer. I'm getting this error when I try to use VS intellisense to reference another project. CSharpAddImportCodeFixProvider encountered an error…
EGN
  • 2,480
  • 4
  • 26
  • 39
20
votes
4 answers

How can I configure Roslyn Analyzers in many projects?

I want to enforce code quality and consistent styling in my organization. To do this I plan to add Roslyn Analyzers and StyleCop to my projects. In order to meet with our agreed coding standards, these analyzers will need additional configuration.…
Jodrell
  • 34,946
  • 5
  • 87
  • 124
19
votes
2 answers

Getting type from a symbol in roslyn

What is the best general purpose way to get a System.Type from Microsoft.CodeAnalysis.ISymbol for different types of symbols ? (e.g. class declarations, variable, properties, etc) I want to be able to do various checks on the type e.g. as checking…
antiskidwarpdrive
  • 321
  • 1
  • 2
  • 8
19
votes
1 answer

When to use SemanticModel.GetSymbolInfo and when SemanticModel.GetDeclaredSymbol

In some cases, when I'm trying to get the the ISymbol for my syntax node, I'm fail (getting null) when using SemanticModel.GetSymbolInfo but succeed when using SemanticModel.GetDeclaredSymbol. I've attached an example bellow. So my question is when…
Eli Dagan
  • 808
  • 8
  • 14
14
votes
2 answers

What Replaces Code Analysis in Visual Studio 2019?

I'm toying with getting our team and projects ready for VS 2019. Right away, trying to set up Code Analysis for a new project, I find this: So, if this is deprecated (and apparently can't even be used, so I'm thinking "deprecated" really means…
13
votes
3 answers

When to use `silent` code analysis severity?

Analyzer feedback severity levels are explained in the documentation. But in my eyes silent and none severity levels seem both to have the same meaning - "I don't want this rule checked for": For none: Suppressed completely. For silent:…
Imre Pühvel
  • 4,468
  • 1
  • 34
  • 49
12
votes
0 answers

Running DotNet Build Causes Microsoft.Build.Tasks.CodeAnalysis.dll Assembly Conflict

I'm having an issue trying to build a dotnet core project from command line that has these references:
12
votes
2 answers

Roslyn code analyzers - when should I use "this."?

I've always been explicit with my code when using instance members, prefixing them with this. and with static members, prefixing them with the type name. Roslyn seems not to like this, and politely suggests that you can omit this. and Type. from…
Matthew Layton
  • 39,871
  • 52
  • 185
  • 313
11
votes
4 answers

"Analyzer with Code Fix" project template is broken

Short question: How to setup a roslyn code analyzer project with a working unit-test project in Visual Studio 2019 v16.6.2? A few months (and a few Visual Studio updates) ago I experimented with setting up a code analyzer project using the "Analyzer…
René Vogt
  • 43,056
  • 14
  • 77
  • 99
11
votes
0 answers

TypeInfo.IsAssignableFrom in Roslyn analyzer

In my Roslyn analyzer I get Microsoft.CodeAnalysis.TypeInfo of an argument by var argumentTypeInfo = semanticModel.GetTypeInfo(argumentSyntax.Expression); also I have another instance of Microsoft.CodeAnalysis.TypeInfo called targetTypeInfo. Now I…
Cheng Chen
  • 42,509
  • 16
  • 113
  • 174
11
votes
1 answer

How to create an AttributeSyntax with a parameter

I'm trying to use Roslyn to create a parameter that looks something like this: [MyAttribute("some_param")] Now I can easily create the AttributeSyntax but can't figure out how to add an argument to the ArgumentList porperty using the…
devlife
  • 15,275
  • 27
  • 77
  • 131
1
2 3
51 52