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

Dotnet Core - How to dispose of RNGCryptoServiceProvider()

I am getting the warning: Severity Code Description Project File Line Suppression State Warning CA2000 Call System.IDisposable.Dispose on object created by 'new RNGCryptoServiceProvider()' before all references to it are out of scope.…
si2030
  • 3,895
  • 8
  • 38
  • 87
0
votes
1 answer

How can I obtain return type from method passed as an argument in another method with Roslyn?

Lets say that I have a code: public class Test { private readonly IFactory _factory; private readonly ISomeClass _someClass; public Test(IFactory factory, ISomeClass someClass) { _factory = factory; _someClass =…
Jan Kowalski
  • 163
  • 1
  • 7
0
votes
2 answers

Is there any way of checking if an enum has an object value defined in it?

Here is the enum that I have defined: enum LogicalChange { List = SyntaxKind.List, TildeToken = SyntaxKind.TildeToken, ExclamationToken = SyntaxKind.ExclamationToken, DollarToken = SyntaxKind.DollarToken, PercentToken =…
Devanshi Mishra
  • 487
  • 5
  • 15
0
votes
1 answer

Roslyn Analyzer Check if Property Declaration is a Standard Type (int, string, Guid, etc)

I am using Roslyn Analyzer to analyze code and I want to check if a Property Declaration is a Standard Type (for example, string, int, Guid, DateTime, etc). For example I want to analyze the below Code: namespace myApp.Models { public class…
0
votes
1 answer

Roslyn analyzer code fix provider replace string in document

I have identified a node that has a value in its string which my Analyzer correctly identifies. I have then created a CodeFixProvider that can successfully retrieve the string and I then want to replace a certain part of the string. I now want to…
eVolve
  • 1,340
  • 1
  • 11
  • 30
0
votes
1 answer

Is it possible to generate code using Roslyn on build?

Right now I am trying to write custom code generator for mapper using Roslyn. I've tried to use CodeFixProvider, but it only suggests codefix, and you should refactor every part by your hands. And I want to just press F5 to generate all needed…
0
votes
1 answer

AllowNull Attribute in c#8 for netstandard2.0 and net451 raise compilation error

Environment: vs 2019 v16.3.1 in c# netstandard2.0 and net451 project, I use c# 8 nulable reference with attributes. Enable c# 8 in csproj: 8.0 enable In myclass.cs, I use AllowNullAttribute: …
M.Hassan
  • 10,282
  • 5
  • 65
  • 84
0
votes
1 answer

Make ReSharper/Roslyn/Compiler recognize JsonRequiredAttribute

Sometimes, when you create DTOs to deserialize json, you decorate properties with the [JsonRequiredAttribute]: class Car { [JsonRequired] public string Make { get; set; } } However, when you do this while using ReSharper or C# 8 you'll see…
t3chb0t
  • 16,340
  • 13
  • 78
  • 118
0
votes
1 answer

Assembly manifest mismatch package-install doesn't resolve

The manifest error is not resovled, i try my best (even link Roslyn source code to my project ). Below is the portion of code, which generate error. The project is WINFORM and in Element Host load the Roslyn Assembly. Steps to Reproduce the…
0
votes
2 answers

Query regarding Microsoft Security Code analysis extension and Fxcop Analyzer

I want to use Roslyn analyser in our Azure pipelines. And got to know from below link that roslyn analyzer comes along with a plugin called Microsoft Security Code analysis…
0
votes
0 answers

Extension missing when debugging Roslyn analyser in VS2019

I created a new analyzer project in VS 2019 and debugged by pressing F5; all fine. Then applied changes and renamed the 3 projects. When hit F5 for debugging, breakpoints for the the new version won’t hit. Then I browsed the extensions in the…
SamuGG
  • 479
  • 2
  • 8
  • 20
0
votes
0 answers

Is it possible to get a SemanticModel from a project file instead of a DLL?

I am creating a code extractor/inlining tool that will make it easier for me to share snippets of source code. It will ideally take a method that I provide, walk the method's syntax tree looking for references to methods/types in my other…
oscilatingcretin
  • 10,457
  • 39
  • 119
  • 206
0
votes
1 answer

Is there a way to access the current solution source from C# Interactive in Rider?

I'm looking for a way to programatically modify the source in a solution from within Rider (or Resharper). For example, I have an array of tuples with 1000 find/replace (F/R) strings to perform a major refactor, and I might want to find a usage of F…
JSobell
  • 1,825
  • 1
  • 14
  • 10
0
votes
1 answer

Parameter validation for a method using Roslyn

I want to perform parameter validation at compile time for an extension method. Something like this Here is the sample code of my program to validate public class Program { static void Main(string[] args) { var sample = new…
Vijay Nirmal
  • 5,239
  • 4
  • 26
  • 59
0
votes
0 answers

Timing of Roslyn Code Analyzers vs legacy code analysis

I'm trying to make a case for my organization to switch from the legacy code analysis for C# projects to start using Roslyn Analyzers. I think that most people are sold on the idea because of all the benefits it offers (not to mention code analysis…