2,928 questions
1
vote
1
answer
214
views
Using an in-memory assembly as metadata reference in another in-memory assembly in .NET
I'm using Roslyn to compile strings of C# code. I'd like to use the output of one of the compilations as metadata reference for another, but when I try to invoke a method that forces the loading of ...
1
vote
1
answer
641
views
How To Use Roslyn with .NET 7
I want to write a new project with Roslyn Analyzer in .NET 7
My purpose is that to find all references for a method in a project as programmatically.
I loaded the solution like the below code.
...
0
votes
2
answers
1k
views
How can I parse a JSON into a dynamic object allowing access to fields via dot notation using System.Text.Json?
I'm implementing a feature where a user can write an arbitrary expression that needs to be evaluated against some context. Users should be able to write expressions referring to a dynamic JSON payload....
1
vote
1
answer
314
views
How to implement HashCode.Combine using SymbolEqualityComparer
After updating packages to .net7 in roslyn code generation project, has error RS1024 Use 'SymbolEqualityComparer' when comparing symbols for IEqualityComparer implementation of GetHashCode()
public ...
0
votes
0
answers
233
views
Is it possible to manually call a Roslyn Analyzer from a Nuget package in code to analyze external code?
Can you import a Roslyn Analyzer from a NuGet package and manually call/ use them in your own code for analysing an external solution (for example letting it analyze a public git repo that you ...
0
votes
0
answers
572
views
what is the work of roslyn csc.exe and what is the roslyn?
why it throw the error "Could not find a part of the path ... bin\roslyn\csc.exe" ?
One working project failed to compile after I made a fresh checkout. The same commit that before worked ...
0
votes
0
answers
164
views
Nuget code analysis packages give errors when analyzing new features in .NET 6 projects
I have made a Visual Studio extension that can be used within Visual Studio 2022 to upload certain types of files (.cs and .vb) to a code security scanning engine. To do this, I’m using a tool called ...
0
votes
2
answers
128
views
Roslyn CSharpExtractMethodService generate method parameters with global:: prefix, why not simple int[]?
When I extract method from this code, final result have global::System.Int32[] list as parameter in NewMethod:
using System;
public class Program
{
public static void Main(string[] args)
{
...
1
vote
1
answer
202
views
GetOperation returning null for VariableDeclaratorSyntax, VariableDeclarationSyntax, and FieldDeclarationSyntax
In a C# incremental generator I am authoring, beginning from an ArgumentSyntax, I am trying to inspect the inline initializer for a readonly field referenced as a method argument. Understanding that ...
1
vote
1
answer
136
views
Roslyn: generate method optional parameters from reflected interface
Given SomeInterfaceType that has a method with optional parameters:
interface SomeInterface
{
void SomeMethod(int a = 1, string c = "foo",
SomeType e = default, ...
0
votes
1
answer
684
views
How to set up code completion in RoslynPad wpf editor control?
I am a beginner level programmer, trying to create a code editor for C# with RoslynPad. I've added the editor control to my WPF window, and highlighting also works. I would also like to enable code ...
0
votes
1
answer
408
views
Using Source Generator to create simpler method overload
I got a class that currently needs to be registered like this (to work reflection-free)
ViewLocator = new StrongViewLocator()
.Register<MainWindowViewModel>(new ViewDefinition(typeof(...
0
votes
1
answer
406
views
Compiling a solution during runtime with nuget references
I'm currently trying to compile a solution during runtime execution of my own program. This solution is user defined and must have support for any number of projects and in these any nuget dependency ...
1
vote
0
answers
120
views
Roslyn GetDescriptionAsync gives incomplete description
I am trying to explore Roslyn's code completion service. I am able to get the completion list, but when I try to get the description it only returns the type and access modifiers, but not the actual ...
0
votes
0
answers
368
views
Getting the AST node that an attribute refers to in C# using Roslyn
Is it possible to get the property that an attribute refers to using Roslyn syntax analysis? I was able to get the attribute name as follows:
using System;
using System.Collections.Generic;
using ...
1
vote
1
answer
432
views
How do I make Roslyn aka MSBuildWorkspace behave the same way Visual Studio/MSBuild do? (aka "ResolveComReferences problem")
I'm trying to make Roslyn/MSBuildWorkspace work on some older .NET Framework projects. Those occasionally have COM references, some of them incorrect.
Compiling in Visual Studio works with warnings:
2&...
2
votes
0
answers
571
views
Is there a .NET Framework equivalent to Core's AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES")
I am using Roslyn to compile and run C# scripts entered by the user. I would like to dynamically react to the script choosing different assemblies to load (for example, adding 'using System.Net.Http' ...
1
vote
1
answer
175
views
Code Analysis CA1307 & CA1310 not working in new .NET 6 projects
I'm using Visual Studio 2022 (17.4.4), and when I create a new empty .NET 6 project, Code Analysis doesn't work.
According to MSDN, Roslyn Code Analyzers are automatically enabled for every new .NET 6 ...
0
votes
1
answer
120
views
Roslyn Code Analysis: Visual Editing of Rules possible?
If I understand correctly, there are two kinds of code analysis available for C# Visual Studio projects:
The old legacy analyzers (not available for .NET Core and .NET Standard)
Roslyn Code Analyzers
...
1
vote
1
answer
196
views
C# Roslyn - get dependency type out of INamedTypeSymbol
I am trying to find a good solution to finding out whether a dependency on another class in C# is in composition or agreggation.
Is there a better way to do it than like this?
private static ...
1
vote
1
answer
176
views
Is an ISymbol from different compilations considered equal in an IIncrementalGenerator
One of the stated benefits benefits of using the IIncrementalGenerator over ISourceGenerator is that different stages of the pipeline can recognize that the results of the current iteration is the ...
0
votes
2
answers
635
views
Why is this incremental source generator invoked when nothing changes
The following source generator creates a new record type on initialization.
It then selects the symbol for this type in another step, and generates a dummy file with a timestamp.
Since the underlying ...
0
votes
1
answer
86
views
Parsing very large C# files (>50MB) with Roslyn produces CompilationUnit with 0 members
I'm trying to use Roslyn for modifying serializers code generated by svcutil.exe. basically, it contains several dozens medium classes, and two huge classes (reader and writer) that contains a ...
2
votes
1
answer
143
views
How to add a using directive outside a namespace using Roslyn?
I have a CSharpSyntaxRewriter that adds a new using directive to my file:-
public class AddUsingDirective : CSharpSyntaxRewriter
{
public override SyntaxNode VisitNamespaceDeclaration(...
0
votes
0
answers
51
views
How to add a C# constructor using Roslyn? [duplicate]
I am trying to add a constructor to a class using Roslyn. My skeleton code looks like this:
public class AddConstructor : CSharpSyntaxRewriter
{
public override SyntaxNode VisitClassDeclaration(...