2,928 questions
1
vote
1
answer
831
views
Read parameters of attribute created by source generator
I have the following source code generator
[Generator]
public class Generator : ISourceGenerator
{
public void Execute(GeneratorExecutionContext context)
{
var output = @"using ...
0
votes
1
answer
457
views
Custom diagnostic rule not being applied in C# using Roslyn API
I have implemented a custom diagnostic rule in C# using the Roslyn API, but it is not being applied to my code. I have verified that the rule is included in the list of enabled rules in my project's ...
0
votes
0
answers
40
views
How to apply WithTriviaFrom recursively for an IfStatement?
As you can see, only the if statement gets the leading trivia and not the rest of it:
Input:
__Internal.DestroyContext(__arg0);
Current result:
if (IntPtr.Size == 4)
{
...
0
votes
1
answer
45
views
Roslyn C# CodeFix fails for 'Project not Equal'
I've written a CodeAnalyzer/CodeFix using VS Community 17.4.3, and I'm trying to test them with the Visual Studio generated unit test code. The analyzer text runs successfully, and the CodeFix ...
1
vote
1
answer
1k
views
Can't load dll from Roslyn in a source generator
I'm doing a C# source generator and I want the developer to influence the output of the generated types based on a class with a specified interface that he will implement.
The interface is declared in ...
3
votes
1
answer
267
views
Adding class members into specific locations using Roslyn?
I'm using ClassDeclarationSyntax.AddMembers() to add methods to the class. The method appears in the class, but I would like to know how to add the method to a specific place. As of now, they are ...
0
votes
1
answer
185
views
Pass array as input parameter in CSharpScript
I try to run method by CSharpScript.
Method:
public class TaskSolution
{
public int[] Calculate(int[] inputValue)
{
return inputValue;
}
}
I tried this solution:
var script = ...
2
votes
1
answer
822
views
Use SourceGenerator with dependencies in same solution
Hi I'm trying to write a SourceGenerator that uses the Humanizer package (This package is only needed while generating code and should not be added as a reference in the project that uses the ...
2
votes
0
answers
115
views
Different DLLs, different project, same version and name between each, both invoked from the same Console App
I have two DLLs with separate code inside them, but with the same NAME and same VERSION. Neither of these can be changed. They are in two separate C# projects, which do not reference each other, but ...
0
votes
1
answer
683
views
Can't access arguments of attribute from system library using source generator
I am trying to make a source generator for mapping columns from the google bigquery api client to class properties. I'm having trouble getting custom column names from a ColumnAttribute on the ...
0
votes
0
answers
93
views
Why do certain Roslyn symbols have no type information?
This is actually a more general question. I am struggling to understand the conceptual model underlying Roslyn and want to find out more, but am also struggling to find resources.
The specific example ...
1
vote
1
answer
3k
views
SourceGenerator Get all classes which implement an interface decorated by an attribute
I am trying to create a source generator for some automationg purpose. My target types are some classes which implement unknown interfaces. Those interfaces are decorated with a custom attribute. By ...
0
votes
1
answer
1k
views
String interpolation cannot be recognized in visual studio when .net framework is set to 4.6.2
It is an asp.net website project with .net framework 4.6.2, and the C# language level is set to 6.0. While developing code in Visual Studio 2022, below code cannot be recognized.
Console.WriteLine($&...
10
votes
3
answers
1k
views
How to reference local assemblies in roslyn analyzer tests?
I´m creating a roslyn analyzer to check the usage of an attribute from my framework code.
Example:
Framework.csproj
public class ModuleAttribute : Attribute { }
Framework.Analyzer.csproj
[...
0
votes
1
answer
132
views
How does csc/Roslyn resolve assembly version?
I have a console program that has two direct dependencies: ClosedXML v0.97 and ClosedXML.Report 0.2.4. The ClosedXML.Report dependency also depends on ClosedXML, but in a version 0.95.
When I try to ...
0
votes
1
answer
112
views
InsertTokensAfter() How to Add New Token after a. Existing SyntaxToken c# Roslyn
I want to add a <T> after DeserializeObject like JsonConvert.DeserializeObject<T>(json)
Below is how I'm trying to achieve it
var desiToken = node.DescendantTokens().Where(x => x.Text ==...
0
votes
1
answer
2k
views
Configure StyleCop Analyzers (Roslyn) in Rider
I am not able to configure the StyleCop Analyzers (Roslyn) in Rider.
I saw this answered question already, but I cannot find Code Analysis in my project properties.
I also tried Inspections and ...
0
votes
0
answers
130
views
What is required to build project with ISourceGenerator?
I use ISourceGenerator to generate some source.
On my pc all work well. But on build machine output dll doesn't contain generated sources.
Should i install anything else besides net 6 sdk on build ...
6
votes
1
answer
3k
views
Suppress RZ10012 analyser in blazor project
In my blazor project, I get hundreds of RZ10012 warnings:
Found markup element with unexpected name 'Foo'. If this is intended to be a component, add a @using directive for its namespace.(RZ10012)
...
0
votes
1
answer
453
views
Unity Default.ruleset Doesnt Work As Expected / Roslyn Analyzer
Roslyn analyzers and source generators
Expected
Actual
Unity 2021.3.11f1 / Rider 2022.2.3
Analyzers: ErrorProne.NET.CoreAnalyzers
Only logging Assets\Subfolder\RethrowError's error. When I remove the ...
0
votes
0
answers
54
views
Roslyn cannot read the semantic model of the external API
When my project is missing some dependencies, roslyn is unable to read the semantic model of these APIs.
For example: uninstalling the newtonsoft.json dependency, when parsing the
var json = ...
2
votes
1
answer
746
views
.net6 System.Collections.Immutable clashing with nuget dependencies?
I am writing a Roslyn Analyzer project for .net6.0 and migrating this from a .netstandard2.0 project of the same purpose.
It seems the latest Microsoft.CodeAnalysis NuGet dependency (a requirement for ...
0
votes
1
answer
75
views
How can one analyze the contents of an compiled .net.core assembly
Background
We are looking to permit 3rd parties to upload compiled .NET.Core assemblies as plugins into custom AssemblyLoadContexts.
Objective
But the assembly needs the for security issues first, and ...
5
votes
0
answers
2k
views
Visual Studio errors disappear when open file
I'm in the process of updating a library in a larger solution. For this purpose, I have removed the old references in all projects and added new ones.
If I compile the solution now I get about 3000 ...
0
votes
1
answer
281
views
C# Roslyn Compiler Syntaxkind Value Keyword
i am currently using the Syntax API from Roslyn to generate some C# code and i am wondering about a small thing when defining a set accessor like this:
var setAccessor = AccessorDeclaration(SyntaxKind....