Questions tagged [microsoft.codeanalysis]

Formerly known as Project roslyn.

see https://www.nuget.org/packages/Microsoft.CodeAnalysis

69 questions
3
votes
0 answers

Restricting available types/namespaces with CSharpCompilation

Our application parses and compiles user input as C# code and this has introduced some security issues. Usually, a user will create expressions using basic arithmetic operators and functions from the math library. However, it is also possible to…
joacho
  • 111
  • 6
3
votes
1 answer

What is a PatternSyntax in Roslyn

This seems a fairly stupid question and I'm not sure it is suitable for StackOverflow. A user of my tool has reported an error with the message Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.LiteralExpressionSyntax' to…
Phil Jollans
  • 3,605
  • 2
  • 37
  • 50
3
votes
0 answers

System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage not working on async methods using xunit

Quite straighforward. This is generic code from some sandbox experiments. ExcludeFromCodeCoverage seems to be working properly for synchronhous methods. No runsettings or any configuration related to the coverage are in…
3
votes
1 answer

How to pre-compile projects with Roslyn Workspace

I need to compile an ASP.Net web applications (Web Forms and MVC) with pre-compile enabled. I'm using Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace to open the project and emit project level assemblies. I have identified RazorGenerator can be used…
3
votes
2 answers

Visual Studio 2015 Package Extension,referenced dll not copied

Hi I use roslyn Microsoft.CodeAnalysis.Csharp dlls in my vs2015 extension,I upgraded my visual studio extension project to visual studio 2013 to 2015. but only My roslyn dll's are not copied when I want to install extension.My target framework is…
2
votes
0 answers

Visual Studio editorconfig and code analysis is frustrating

In recent years I used ruleset files for code analysis, configured via a project's Properties -> Code Analysis tab. I've recently started creating some .Net 5 projects where this option is no longer available, so I've decided to try using an…
2
votes
1 answer

Determining if a private field is read using Roslyn

I've been searching all day and have read many posts but I just can't quite come to a conclusion on this. I'm trying to create a Roslyn analyzer to report a diagnostic when a private field is unread. Registering the syntax action and finding out if…
Duu82
  • 157
  • 2
  • 11
2
votes
1 answer

Is there a way to "cap" RoslynPad's Roslyn's IntelliSense?

I'm actually integrating the amazing RoslynPad into a WinForms application and working damn well. The point of the integration is allowing the user to type in some C# code so it can be used in a future. Thing is I'm interested on "capping" the user…
Gonzo345
  • 1,133
  • 3
  • 20
  • 42
2
votes
1 answer

SyntaxWalker Visitor doesn't visit Methods

I got this walker internal class MyWalker : CSharpSyntaxWalker { public int MethodCount { get; private set; } public MyWalker() : base(Microsoft.CodeAnalysis.SyntaxWalkerDepth.Trivia) { } public override void…
Boas Enkler
  • 12,264
  • 16
  • 69
  • 143
1
vote
1 answer

Roslyn - OutOfMemoryException due to assemblies loaded in memor

We are doing extensive code analysis on a LOT (thousands) of C# projects. But although we are not calling the Solution.Emit() method, assemblies are still loaded into memory. Are there other methods that also cause this behavior? Is it even possible…
TWT
  • 2,511
  • 1
  • 23
  • 37
1
vote
2 answers

How to get all analyzers rules in a solution

I have added some analyzer via NuGet in my solution. How to get all added analyzer rules from NuGet references? I need the ID (e.g. CA1001) and descriptions of all my enabled analyzers. EDIT: I need some C# code to do this.
1
vote
0 answers

System.IntPtr and nint in C# Microsoft.CodeAnalysis

In a normal comparison of types typeof(nint)==typeof(System.IntPtr) is true so I was expecting that the SpecialType of System.IntPtr is nint, just like System.Int32 and int, when doing CodeAnalysis using Microsoft.CodeAnalysis. but it turns out the…
1
vote
1 answer

Find symbols of deriving interfaces in solution and referenced assemblies

What I am trying to do (working with Roslyn/Microsoft.CodeAnalysis) I'm trying to find all symbols of interfaces which are inheriting from a specific interface, in the solution as well as referenced assemblies. My goal is to do that as efficient and…
Alex
  • 569
  • 5
  • 21
1
vote
1 answer

AssemblyDependencyResolver not resolving

I'm trying to create a custom AssemblyLoadContext utilizing an AssemblyDependencyResolver in C# under Net Core 3.1 (Visual Studio 2019). But while I can see AssemblyDependencyResolver as a public sealed class in the Object Browser, neither…
Mark Olbert
  • 6,584
  • 9
  • 35
  • 69
1
vote
1 answer

How to get to Workspace in DiagnosticAnalyzer and CodeFixProvider? (Roslyn)

I want to check whether the configuration of a Method (Like Logger) is added to appsettings.json. If not, then I want to add it through Code Fix. I am trying to access the Workspace so that I can access the documents in it. But I can't find a way to…
Vijay Nirmal
  • 5,239
  • 4
  • 26
  • 59