2,928 questions
1
vote
0
answers
22
views
Problem with Roslyn configuration on neovim
I've been trying to setup roslyn.nvim with rzls.nvim on my neovim for a while to work with .NET, C# and Blazor. But I've been facing some frustrating problems, I'm using WSL Ubuntu 24.04, a neovim ...
0
votes
0
answers
228
views
C# Dev Kit on an Air Gapped Network
I am on an air gapped network trying to run a C++ project that uses solution files from Visual Studio, because that is what the rest of my team uses.
I have:
C# Dev Kit 1.61.22
C# 2.93.21
.NET ...
2
votes
0
answers
50
views
Getting CSharpCompilation error diagnostics despite seemingly having all the right settings [duplicate]
Here is my code:
var compilation = CSharpCompilation.Create(asmProps.AssemblyName, syntaxTrees, references,
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary,
...
3
votes
1
answer
154
views
How to cause the CA2254 warning in your own library?
Let's say I want to wrap the classical LogInformation() method with a custom one:
public static void Info(this ILogger log, string message, params object[] objects) {
// ... some custom logic
...
2
votes
1
answer
98
views
Which methods to use to bind SyntaxNodes to Symbols and which SyntaxNode types can be bound?
Using the Roslyn SDK, which SyntaxNode (derived) types can be bound to Symbols, and which methods are used to bind them?
So far, I am aware of SemanticModel.GetSymbolInfo(), SemanticModel....
3
votes
2
answers
2k
views
Error RS1035 "The symbol is banned for use by analyzers" while using GeneratorExecutionContext.AddSource method
Beginner to Roslyn Source Generators here.
I'm following the documentation on Source Generators by Microsoft. I have created a .NET Standard 2.0 Class Library, and set the following as the contents of ...
2
votes
0
answers
68
views
How to specify target framework for Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScript?
The problem
I am implementing an out-of-process C# REPL for a Unity game. I tried an in-process REPL at first, but couldn't get it to work because of some weird VTable related exceptions when loading ...
238
votes
17
answers
263k
views
Can I convert a C# string value to an escaped string literal?
In C#, can I convert a string value to a string literal, the way I would see it in code? I would like to replace tabs, newlines, etc. with their escape sequences.
If this code:
Console.WriteLine(...
0
votes
0
answers
142
views
Why doesn't my incremental C# code generator run?
I am writing a code generator to add functions to existing interfaces and that sort of thing. But I can't even get the project to launch.
To be clear, it builds, compiles, goes through all the motions,...
91
votes
9
answers
55k
views
Is it possible to compile a single C# code file with the .NET Core Roslyn compiler?
In old .NET we used to be able to run the csc compiler to compile a single .cs file or several files.
With .NET Core we have dotnet build that insists on having a proper project file. Is there a ...
217
votes
5
answers
85k
views
Can the C# interactive window interact with my code?
In Visual Studio 2015 or later, I can open the 'C# interactive window', and run code:
> 5 + 3
8
That's cute. Now how can I interact my code—my classes? Assume I have a project open.
> new Cog()...
0
votes
0
answers
114
views
C# Source generator accessing code from "Referenced Project(s)"
I'm writing a source generator which will generate factories to create instances of object(s).
Since the source generator generates code that's related to tests, I'm going to install the source ...
3
votes
1
answer
331
views
How to ban an entire namespace with BannedApiAnalyzers?
I am trying to ban the usage of Newtonsoft.Json package in my codebase, and I am trying to use the BannedApiAnalyzers Nuget package (latest stable version, 3.3.4).
My problem is that while I am able ...
1
vote
1
answer
64
views
Roslyn's AllInterfaces returns nothing for List<> and Dictionary<>
In a source generator, I'd like to determine if a member is IEnumerable or IDictionary. In the sample below, the array member returns IEnumerable, etc. from AllInterfaces, but I get zero interfaces ...
0
votes
0
answers
194
views
Accessing the intermediate node model of razor parser
As part of a Roslyn Analyzer (C#), I would like to access the intermediate model of Razor parser to check the content for project specific coding guidelines.
// Referenced NuGet:
// <...
6
votes
1
answer
2k
views
How to use Banned API analyzers in my own code
Roslyn has banned analyzers feature. I want to use in my own code that compiles code dynamically (own scripting engine based on C# lang) via CSharpCompilation class with WithAnalyzers extension method....
166
votes
4
answers
28k
views
In which language is the C# compiler written?
I looked at the source code at http://referencesource.microsoft.com/, and it appears all the source code is in C#.
I also looked at the source code for the new C# compiler platform (Roslyn), and it ...
1
vote
0
answers
93
views
How does .editorconfig interact with Visual Studio IntelliSense and .NET build?
I notice that there are mismatches happening in errors and warnings detected by Visual Studio, a locally executed dotnet build <Solution> and the dotnet build <Solution> executed by the CI/...
0
votes
1
answer
120
views
How can I execute C# code using Roslyn from a string and use global variables from a Dictionary<string, object>?
I'm working on a C# application where I need to execute C# code provided as a string input using Roslyn. The challenge is to execute this code and access global variables stored in a Dictionary<...
0
votes
1
answer
66
views
Roslyn Diagnostic Analyzer Context Node Location Past End of File
I have developed my first diagnostic analyzer and installed it into a test project via NuGet. Everything works find, except that no red line is shown under the issue. I am using context.Node....
0
votes
1
answer
28
views
Rosyln C# code fix not removing multiple nodes
I am in the process of developing a C# roslyn code analyzer and code fix and am struggling with the proper code to perform the code changes.
The analyzer and code fix logic itself does (hopefully) not ...
1
vote
0
answers
265
views
How can I create a single NuGet package that's targetting .NET 9 and .NET Framework 4.8.1 at the same time?
I'd like to create a NuGet package for a WPF library component that I'm writing.
As I'm using WPF classes, I cannot use .NET Standard. So, I need to target .NET 9 and .NET Framework 4.8.1 at the same ...
122
votes
5
answers
38k
views
Microsoft Roslyn vs. CodeDom
From a press release yesterday on InfoWorld regarding the new Microsoft Roslyn:
The most obvious advantage of this kind of "deconstructed" compiler is
that it allows the entire compile-execute ...
1
vote
1
answer
282
views
How to create CodeAnalysis analyzer for razor files?
I'm creating custom roslyn analyzers in order to enforce custom code style rules in my project. So far it's been going well with the help of AI generators for .cs files. However I cannot get an ...
0
votes
0
answers
137
views
How to get the Symbollnfo (or TypeSymbol) of ObjectCreationExpressionSyntax via MemberAccessExpressionSyntax
I use Roslyn to analyze field initializations. One of the analysis target is the following field.
private static readonly ImmutableDictionary<int, int> _Map =
new Dictionary<int, int> { ...