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

Why does TFS 2015 SP3 Build Agent fail when adding Microsoft.CodeAnalysis.NetAnalyzers?

Ran into this issue again, but the previous solution doesn't apply (removing Microsoft.Net.Compilers v3.8.0 via Nuget - this package doesn't exist in this solution)... We have a VS2019 solution that we just replaced the old Microsoft FXCop Code…
Alex A
  • 59
  • 10
0
votes
0 answers

Get analyzer results through Roslyn API

My company has been developing a static analysis tool using the Roslyn API since it was in beta. Currently we use Microsoft.CodeAnalysis and Microsoft.CodeAnalysis.Workspaces.MSBuild version 3.6.0, our tool opens projects with MSBuildWorkspace, and…
Tejes
  • 144
  • 1
  • 10
0
votes
0 answers

What is the best method for Replacement of Map() in EF Core 3.1

I have implemented the project of EntityFramework 6 into EntityFramework Core 3.1. Using Roslyn API, I have to do migrate the Mapping the entity to tables in Entity framework. I have no idea about this. Sample.cs protected override void…
0
votes
1 answer

Get default namespace from existing csproj (Microsoft.NET.Sdk format)

So, I am writing a code generator tool and I want to get the default namespace from an existing csproj that the user will have to specify. Essentially I want to be able to load the csproj from a path and get some configuration from it. I also want…
Carlos Jimenez Bermudez
  • 1,070
  • 1
  • 14
  • 36
0
votes
0 answers

Replace HasOptional() using Roslyn c#

I have implemented the project of EntityFramework 6 into EntityFramework Core 3.1. I am new to Roslyn API. Sample.cs protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() …
0
votes
1 answer

Nullable Interface does not trigger CS8602

I've encountered a few times now where I have nullable enabled and a property or field marked as a nullable interface type (with an appended ?), then if I go to use the property or field without a null check, I receive no error. (I would expect…
ehiller
  • 1,346
  • 17
  • 32
0
votes
1 answer

Reverse engineer display string of ISymbol

I am using Microsoft.CodeAnalysis.PublicApiAnalyzers to get the text representation of public apis of my app. The text for a public api, for example the default constructor of a class A, is A.A() -> void The source code of the analyzer uses this…
Mr Balanikas
  • 1,657
  • 15
  • 28
0
votes
1 answer

Loading projects using Microsoft.VisualStudio.LanguageServices throws System.ArgumentNullException for Visual Studio 2017

I am trying to enumerate all projects of a solution using Microsoft.VisualStuio.LanguageServices. This is working fine for VisualStudio 2019 but it is failing on VisualStudio 2017. My code is as bellow- var workspace=…
0
votes
1 answer

Does Roslyn support code fix actions for project/compilation-level diagnostics (with no location)?

Let's report some diagnostic and register code fix for this diagnostic. private static void OnCompilation(CompilationAnalysisContext context) { var compilation = context.Compilation; var diagnostic = Diagnostic.Create( Rule, (Location) null…
Denis535
  • 3,407
  • 4
  • 25
  • 36
0
votes
1 answer

custom code analysis on cshtml files with sonarqube

We are developing an MVC .NET Core project with VS19. We are also using Devextreme. We have several cshtml files with devextreme components and templates. Templates in DevExtreme ASP.NET MVC Controls support ERB-style syntax. The following…
syc
  • 163
  • 1
  • 8
0
votes
1 answer

Whats the difference between the 'Code Refactoring' and the 'Analyzer with Code Fix' template

I thought I'd delve into writing a custom code analyzer, so that I can enforce a rule and and allow code fixes to be applied. Upon opening VS after installing the required workload I see the following available templates: Code Refactoring Analyzer…
sommmen
  • 6,570
  • 2
  • 30
  • 51
0
votes
0 answers

c#: how to enforce classes Presentation Layer from calling Dal Layer?

I'm looking for a Roslyn check / Resharper Annotation / Postsharp or any extension of Visual Studio where I can force a class from the UI to not call the Dal.
Revious
  • 7,816
  • 31
  • 98
  • 147
0
votes
1 answer

Why does few analyzer rules have their effective severity set to suppressed in .NET4.6

After adding code quality NuGet packages, I can see that by default, the effective severity level for some rules is set to suppress. But their default severity level remains warnings. Severity set as suppress not as warning How can I set the…
0
votes
1 answer

RoslynCodeAnalysisService exception when coding

While using VisualStudio 2019 with my own source generator. I'm having an exception inside visual studio and it prompts me to open a debugger. This only happens while coding and not while building (which make me thinks that my source generators is…
Yann
  • 1,388
  • 2
  • 11
  • 9
0
votes
2 answers

Get the actual enum type from a nullable enum type in a switch statement during roslyn analyis

I would like to analyse a switch statement, that uses a "nullable enum" to decide. I have the following class that I would like to analyze: namespace Common.Model.Schema { public enum ModuleType { Case1, Case2, Case3 …
Jannik
  • 2,310
  • 6
  • 32
  • 61