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
0 answers

I am writing an application to extract different parts of a C# script

I am using the CSharpSyntaxTree and I have been able to extract the using statements, method and class definitions.The structure of my script is:
Yusuff Sodiq
  • 815
  • 2
  • 12
  • 19
0
votes
1 answer

compilation.Emit(..) create typeOf(T) with constructor params

I'm using RazorEngine for Razor Template parsing and trying to make use of its Roslyn code. I know my issue is that I'm using a base-type (ViewBase) in my razor views, and it's not being constructed (As it has a ctor parameter). However after…
Stuart.Sklinar
  • 3,683
  • 4
  • 35
  • 89
0
votes
1 answer

Unable to Upload (analyzer and code fix extension) to Nuget

I am trying to upload the analyzer and code fix extension to Visual Studio gallery It's throwing an error. I have chosen the visual Studio code of extension type of the three available options which I attached in the image. Am I using the correct…
0
votes
1 answer

Why have I more spelling errors (CA1704 rule) in VSTS?

I forced Code Analysis execution on VSTS (with Hosted2017 agent) to build a VS2017 solution using .NET framework 4.6.1. But I don't have the same spelling errors (CA1704 rule) on VSTS and on my machine with VS2017 Enterprise. On my machine, I fix…
Phil
  • 1,035
  • 2
  • 10
  • 17
0
votes
2 answers

Roslyn semantic analysis on CSharpScript doesn't seem to work

I'm taking a look at being able to perform semantic analysis on C# scripts created via the CSharpScript API in Roslyn. However, all of my attempts to use the semantic model API have failed. Here's my code, containing my methods so far and the stuff…
0
votes
0 answers

How to get all the referenced syntax trees for a given syntax tree

I need to get all the syntax trees that referenced to a given syntax tree. Following is my use case: User selected the Class1.cs which has a reference from Class2.cs,Class3.cs,... Requirement: I need to get all the syntax trees which are referenced…
Bandara
  • 780
  • 8
  • 29
0
votes
1 answer

Roslyn .net compiler - Solution Startup projects

How to find the solution startup projects. The solution is loaded in to MsBuildWorkspace and compiled successfully. Project dependency graph does not have a method to find this information.
sss
  • 21
  • 1
  • 5
0
votes
1 answer

Cannot get internal members of a Type from within INamedTypeSymbol

I am getting a referenced type from a Roslyn compilation by using Compilation.GetTypeByMetadataName(...) method. Then I use INamedTypeSymbol.GetMembers() method to get all its member symbols. I am getting all public and protected symbols but neither…
Nick Polyak
  • 201
  • 1
  • 9
0
votes
1 answer

Get CLR Type of Segments in an InvocationExpressionSyntax

I've extracted all InvocationExpressionSyntax's from a parsed C# script with results like: 1. System.IO.Directory.GetDirectories(@"c:\").First() 2. Math.Sin(3).ToString() 3. value.Substring(0, 1) I also have the SemanticModel object and have…
Raheel Khan
  • 14,205
  • 13
  • 80
  • 168
0
votes
1 answer

How to modify Solution/Project object?

I have defined attribute MyAttribute : Attribute that is supposed to be used exactly once within a class (only one constructor per class may have it and it can appear only once on ctor’s attribute list). I have created a Roslyn analyzer to check…
user3284063
  • 665
  • 5
  • 20
0
votes
1 answer

Roslyn: Declare variables and then list them

What I'm looking for seems to be overlapping the scripting and compiling features of Roslyn compiler as such I am confused as to which one I should be using. I'd like to declare/define variables (and evaluate their values) as I go along and at some…
Jeff Saremi
  • 2,674
  • 3
  • 33
  • 57
0
votes
1 answer

Find references of a private member in Roslyn

I want to find all the references of a private member of a class. I've tried to do this: MemberInfo member = ...//the private member for which I want to find its references Type type = member.DeclaringType; string assemblyName =…
Tamas Ionut
  • 4,240
  • 5
  • 36
  • 59
0
votes
1 answer

C# CodeFixes: Minimum Requirement that codefix is displayed

I recently started with CodeAnalyzers and CodeFixes. Of course the template coming with the sdk () works. But when I move on, the codefix does not show up anymore on debugging. When walking through the diagnostic is created as it is supposed to…
Tobias
  • 2,945
  • 5
  • 41
  • 59
0
votes
2 answers

Can a CodeFixProvider be used to change more than one document?

I have a CodeFixProvider that can change a document, and it works. But I also need to change a second document when the first document is changed. I can write the code to fix the second document, but I wouldn't know when to execute it, because I…
Martin Lottering
  • 1,624
  • 19
  • 31
0
votes
0 answers

FindReferencesAsync does not find references in one particular solution

I'm trying to find the references to a method in the entire solution. Below is the code snippet. The same snippet works fine for all the solutions except one. I've subscribed to the workspaceFailed event and there are no workspace or solution load…
DevD
  • 41
  • 2