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

How to specify Marshalling for the function MAPISendMail

Since upgrading to Visual Studio 16.8.1, I am getting many errors from the code analysis in my (somewhat old) VB.NET project. One error is on the following DLLImport _ Private Shared Function MAPISendMail ( ByVal sess …
0
votes
1 answer

Parsing source file and trying to get its methods doesn't work. Why is it not working?

private static void Main(string[] args) { var syntaxTree = CSharpSyntaxTree.ParseText(@"C:\Users\Umut\source\repos\frmMain\Program.cs"); var tree = syntaxTree.GetRoot(); var methods =…
Nope
  • 53
  • 7
0
votes
1 answer

Roslyn: detect when a local variable has been declared with `using`

I'm writing a C# source generator (similar to analyzer) and I'm trying to determine if a local variable (ILocalSymbol) is readonly due to being declared with a using directive. Specifically the following case: using System; struct Container :…
Joel
  • 352
  • 1
  • 3
  • 11
0
votes
0 answers

Masstransit Analyzers

In a brand new c# project Using Masstransit.Analyzers nuget package (https://masstransit-project.com/learn/analyzers.html#message-initializers) If i call IPublishEndpoint.Publish(new { random="fields"}) as expected a message is…
0
votes
0 answers

Check if a method is invoked inside another method in all execution paths by Roslyn

Using Roslyn, how can I check the body of a method to determine whether another method is always invoked before returning? For example, in an OWIN middleware, I want to check if the next method is called in all execution paths. try { await…
Khodaie
  • 346
  • 4
  • 17
0
votes
2 answers

How to configure SonarAnalyzer.CSharp S1451 Track lack of copyright and license headers when using .editorconfig

I am not using SonarQube local server, or SonarCloud, or SonarLint. I instead just reference the SonarAnalyzer.CSharp nuget package directly in each of my .NET Core projects and configure the rule severity using .editorconfig (more info) How can I…
0
votes
1 answer

Could not load type Microsoft.Build.Framework.SdkResultItem

I have a application that uses Roslyn API to analyze C# code inside separated solutions; After some Visual Studio updates, i'm receiving this error in my application: Msbuild failed when processing the file '{separated solution .csproj file}' with…
0
votes
1 answer

CA1707 warning on constants names

why microsoft keeps documenting code with constant like WM_SOMECONSTANT but the code analysis in Visual Studio reports the CA1707 warning? Should we suppress all these warning for the solution? should we rename all the constants?
0
votes
1 answer

Connect code to using statement with Roslyn

Is there anyway to connect a piece of code to its "using" statement using the Roslyn framework? For example, given this piece of code: using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using…
Matt
  • 384
  • 2
  • 10
0
votes
1 answer

Roslyn: Reconstruct code from BasicBlocks in a CFG

In Roslyn, a control flow graph has the list of BasicBlocks which constitute the program. Is it possible to get code statements from each block to reconstruct the entire code?
0
votes
1 answer

Add CodeFixProvider to existing Nuget package

I'm trying to add a Roslyn Analyzer and Code Fix Provider to an existing project, ApiEndpoints.csproj that is distributed as a nuget package. When consuming the nuget package in a new Visual Studio instance, the Analyzer is clearly working, but the…
Philip Pittle
  • 11,821
  • 8
  • 59
  • 123
0
votes
1 answer

Visual Studio Compiles Successfully but Roslyn Balks

I'm writing a C# code analyzer and running into a problem. The following source code file: using System; namespace J4JSoftware.Logging { // added to test SharpDoc [AttributeUsage( validOn: AttributeTargets.Class |…
Mark Olbert
  • 6,584
  • 9
  • 35
  • 69
0
votes
2 answers

How to get all C# types or namespaces that Roslyn couldn't find?

I'm using Roslyn to parse a C# project. I have a Microsoft.CodeAnalysis.Compilation object that represents this project. However, this project might not have been compiled successfully; there may be several reasons for this, but I'm specifically…
JesseTG
  • 2,025
  • 1
  • 24
  • 48
0
votes
0 answers

Visual Studio extension to refactor XAML

I'd like to create an extension for XAML (WPF) which will work like this: In a XAML file, when you right click on an element tag (i.e.
Don Box
  • 3,166
  • 3
  • 26
  • 55
0
votes
2 answers

Gets TypeSyntax's namespace from external assembly

I'm trying to retrieve some type's namespace with Roslyn API, but my code is not working with external assemblies (types from NuGet packages, or from another external assembly): var typeInfo = semanticModel.GetTypeInfo(typeSyntax); var isFromSource…