CSharp Compiler API — Validate C# Code (Roslyn Diagnostics) avatar

CSharp Compiler API — Validate C# Code (Roslyn Diagnostics)

Pricing

from $0.005 / snippet check

Go to Apify Store
CSharp Compiler API — Validate C# Code (Roslyn Diagnostics)

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

IHNDEV

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

10 days ago

Last modified

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

FieldTypeDefaultNotes
modesnippet | projectsnippetSnippet = in-memory semantic check. Project = full dotnet build with NuGet support.
codestringSource to check (snippet mode). Top-level statements, classes, or full files.
filesarrayProject mode: { "path", "content" } objects. A .csproj is generated if you don't include one.
targetFrameworkstringnet8.0net8.0, net9.0, net6.0, netstandard2.0
languageVersionstringlatest813 or latest
outputKindstringconsoleconsole allows top-level statements; classlib for libraries
nullablebooltrueNullable reference type analysis (CS86xx warnings)
treatWarningsAsErrorsboolfalse
strictboolfalseAlso runs the emit phase (in memory, discarded) for the rare emit-only diagnostics
packagesstring[]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

EventPriceWhen
Snippet check$0.005Per snippet-mode run — a typical validation costs half a cent
Project check$0.03Per project-mode build (includes NuGet restore)
Actor start$0.001Per 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 status message — 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.