CSharp Compiler API — Validate C# Code (Roslyn Diagnostics)
Pricing
from $0.005 / snippet check
CSharp Compiler API — Validate C# Code (Roslyn Diagnostics)
Compile-check CSharp code and get structured compiler errors and warnings as JSON. Semantic Roslyn analysis of .NET (dotnet) syntax and types — no build artifacts, no code execution. Built for AI agents verifying LLM-generated code.
Pricing
from $0.005 / snippet check
Rating
5.0
(1)
Developer
IHNDEV
Maintained by CommunityActor stats
0
Bookmarked
2
Total users
1
Monthly active users
10 days ago
Last modified
Categories
Share
C# Compiler API — Validate .NET Code & Get Roslyn Diagnostics
Check C# code and get every compiler error and warning back as structured JSON — exact codes, messages, and line/column positions. Full semantic Roslyn analysis, no build artifact, no code execution.
Input:
{ "mode": "snippet", "code": "Consle.WriteLine(\"hi\");" }
Output:
{"success": false,"errorCount": 1,"diagnostics": [{"id": "CS0103","severity": "error","message": "The name 'Consle' does not exist in the current context","file": "snippet.cs","line": 1,"column": 1}],"checkTimeMs": 412}
Why AI agents need this
LLMs generate C# they cannot compile. One call answers "does this build?" with exact error locations — enabling the loop that makes generated code reliable: generate → check → fix → check. Diagnostic IDs are raw compiler codes (CS0103, CS8602…), so an agent can look them up, fix them, or suppress them deliberately.
Quick start
API:
curl -X POST "https://api.apify.com/v2/acts/<USERNAME>~dotnet-check/run-sync-get-dataset-items?token=<TOKEN>" \-H "Content-Type: application/json" \-d '{ "mode": "snippet", "code": "var x = 1 + \"two\";" }'
MCP (agents): add this actor at mcp.apify.com?tools=<USERNAME>/dotnet-check.
Input reference
| Field | Type | Default | Notes |
|---|---|---|---|
mode | snippet | project | snippet | Snippet = in-memory semantic check. Project = full dotnet build with NuGet support. |
code | string | — | Source to check (snippet mode). Top-level statements, classes, or full files. |
files | array | — | Project mode: { "path", "content" } objects. A .csproj is generated if you don't include one. |
targetFramework | string | net8.0 | net8.0, net9.0, net6.0, netstandard2.0 |
languageVersion | string | latest | 8–13 or latest |
outputKind | string | console | console allows top-level statements; classlib for libraries |
nullable | bool | true | Nullable reference type analysis (CS86xx warnings) |
treatWarningsAsErrors | bool | false | |
strict | bool | false | Also runs the emit phase (in memory, discarded) for the rare emit-only diagnostics |
packages | string[] | — | Project mode: Id@Version, e.g. Newtonsoft.Json@13.0.3 |
Output reference
Each run pushes one dataset item: success, errorCount, warningCount, checkTimeMs, toolVersion, chargedEvents (billing transparency), and diagnostics[] — always present, errors first, each with id, severity, message, file, line, column, endLine, endColumn.
Pricing
| Event | Price | When |
|---|---|---|
| Snippet check | $0.005 | Per snippet-mode run — a typical validation costs half a cent |
| Project check | $0.03 | Per project-mode build (includes NuGet restore) |
| Actor start | $0.001 | Per run |
Security model
- Your code is never executed. The default path performs semantic analysis only — no assembly is ever produced. Strict mode emits to memory and immediately discards it.
- No user-supplied analyzers or build tasks are ever loaded — these would execute arbitrary code at compile time, so they are excluded by design.
- Sources are discarded after the run. Nothing is logged or persisted beyond your own dataset output.
Limits & good to know
- Snippet source up to 1 MB; project mode up to 100 files / 5 MB / 25 packages.
- Common NuGet packages restore from a prewarmed offline cache; unusual ones fetch from nuget.org and take longer.
- Project mode has a 120 s build timeout.
- Policy limits exit gracefully with a
statusmessage — they are never disguised as system errors.
Roadmap
nuget-audit (vulnerability scanning), dotnet-format-check, F#/VB.NET checkers. Found an issue or need a feature? Open an issue on this actor — response time is part of the deal.
