v0.1.0-preview.13 C# source generator for Blazor

Write Blazor Interactive Auto services once.

You write an interface and one server implementation. The generator writes the WebAssembly HttpClient proxy, the API endpoints and the DI registrations, at compile time.

dotnet add package Blazor.AutoGen --prerelease
MIT licensed .NET 10 429 tests MAUI Hybrid
// You write this. Nothing else.
using Blazor.AutoGen;

[Remote]
public interface IWeatherService
{
    Task<WeatherForecast[]> GetForecastAsync(int days);

    [Authorize]
    Task<string> GetSignedInUserAsync();
}
● Build succeeded0 errors · 0 warnings
the problem

Interactive Auto means writing every service twice.

A component runs on the server first, then in the browser on WebAssembly, where it can't reach your database. So every service needs five pieces kept in sync by hand. The Blazor team tracks this as dotnet/aspnetcore#60312.

Today Five pieces per service

  • 1IWeatherService interface
  • 2WeatherService server implementation
  • 3WeatherClient with HttpClient calls
  • 4MapGet / MapPost(...) endpoint per method
  • 5DI registrations in two Program.cs files

With Blazor.AutoGen Two

  • 1[Remote] IWeatherService interface
  • 2WeatherService server implementation
  • HttpClient proxy, generated
  • Endpoints, generated
  • DI registrations, generated

Only the first two are in your repository. The compiler generates the rest on every build, so there's nothing to commit or keep in sync.

how it works

Same component. Two call paths. Zero changes.

Your component injects the interface. Where it runs decides what it gets.

Component@inject IWeatherServiceRazor, @rendermode InteractiveAuto
GeneratedWeatherServiceProxyHTTP to /_remote/..., JSON back
Your codeWeatherServiceDatabase, files, secrets

Prerendering and Interactive Server resolve WeatherService straight from DI. A direct method call, no HTTP, no serialization.

quick start

Up and running in four steps.

Moving an existing app? Add [Remote], then delete your hand-written client service, endpoint and registrations.

<!-- Server.csproj and Client.csproj.
     Source generators don't flow through project references,
     so each project gets its own reference. -->
<PackageReference Include="Blazor.AutoGen" Version="0.1.0-preview.13" />
features

Everything a hand-written client does.

Generated code is plain, internal C# you can read in your IDE, rebuilt by the compiler every time, so none of it lands in your repository. It plugs into the ASP.NET Core features you already use.

Your auth, unchanged

[Authorize], roles, policies, cookies, Identity and JWT bearer all work. Signed-out calls get a 401, never a redirect, and GET and DELETE endpoints refuse cross-site links and embeds (CSRF), on by default.

Call filters and logging

IRemoteCallFilter wraps every proxy call like middleware: rewrite arguments, add headers, short-circuit, retry, or log failures to your own logger.

Routes your way

Name routes per interface or method, or match your controllers project-wide with RemoteConvention.

Every HTTP method

GET, POST, PUT, PATCH and DELETE, picked from the method name or set with [Remote(Method = ...)]. GET and DELETE send exact, culture-proof query strings.

Methods from names

By default GetAsync is a GET, UpdateAsync a PUT, DeleteAsync a DELETE, with nothing to set up. Wrong methods get a proper 405.

Smaller responses

Opt in with compressResponses: true and large results go out Brotli-compressed, about 80% smaller.

Mistakes fail the build

Duplicate routes, controller clashes and DTOs that won't survive JSON are compiler diagnostics, not runtime surprises.

MAUI Blazor Hybrid

The same proxies run in .NET MAUI, WPF and WinForms hybrid apps, pointed at your server with your own HttpClient.

Server-only by choice

Opt in per method with [Remote]. Unmarked methods get no endpoint, so server-only operations are never exposed.

Token refresh and retries

Request bodies can be resent, so your DelegatingHandlers, Polly policies and 401-refresh patterns work as they are.

JSON you control

System.Text.Json on the wire, configured once for both sides. Newtonsoft MVC controllers can live next to it.

Built fresh, never committed

The compiler generates the code on every build and caches it between edits, so your IDE stays fast even with 100 remote interfaces. Nothing generated goes into git.

performance

As fast and as small as code you'd write by hand.

Speed: BenchmarkDotNet on real Kestrel over loopback. Size: the sample app published for WebAssembly, compared file by file. .NET 10, Release, one developer machine; compare the numbers with each other, not as absolutes.

1–2%
time overhead vs. a hand-written HttpClient call and endpoint
+0.25%
WebAssembly download (Brotli) vs. the leanest hand-written clients; smaller than typical ones past ~80 methods
0.2 ms
per IDE keystroke with 10 remote interfaces
429
tests across auth, JSON, HTTP methods, concurrency, HttpClient and routing

Mean time per call (µs), lower is better

Hand-written, int
100.9 µs
Generated, int
102.8 µs
Hand-written, record
105.9 µs
Generated, record
106.5 µs
Hand-written minimal API + HttpClientGenerated endpoint + proxy

The generated types are sealed classes, not structs: JsonContent would box a struct request anyway, and every struct type would get its own copy of the generic call code, growing the download. A call takes about 100 µs, mostly network and JSON.

WebAssembly download with Brotli, 311 remote methods (MB), lower is better

Hand-written, minimal
3.026 MB
Generated proxies
3.044 MB
Hand-written, typical
3.074 MB
Same app, hand-written HttpClient clientsSame app, generated by Blazor.AutoGen

The sample app published in Release with 300 extra methods. Per method the generated code costs about 58 bytes, one-async-method-per-call clients about 184 and the leanest helper-based clients about 20; with a fixed cost of about 8 KB, the generated code is smaller than the typical style from about 80 methods on. .NET 8, 9 and 10 apps get the package's net8.0 build, so they don't download the netstandard.wasm compatibility file.

compile-time safety

Catch it in the build, not in production.

The generator checks your contracts as you type and points at the exact line.

  • Two remote endpoints on the same route, across projects too
  • A remote route that clashes with a controller action
  • DTOs that only Newtonsoft can read, which break once WebAssembly takes over
  • GET and DELETE parameters that can't travel in a query string
  • #pragma and .editorconfig severities work as usual
See all rules
error BAG011: Two remote endpoints share a route
error BAG012: Remote route matches a controller action
warning BAG010: DTO relies on Newtonsoft [JsonProperty]
error BAG016: GET parameter can't go in a query string
warning BAG008: Parameter type can't be sent as JSON
info BAG014: Your controllers use a route pattern;
  add [assembly: RemoteConvention("api/[service]/[method]")]
runs where blazor runs

One interface. Every host.

The generator looks at what each project references and emits exactly what it needs.

Blazor Web App Blazor WebAssembly ASP.NET Core Web API .NET MAUI Blazor Hybrid WPF / WinForms Hybrid Console and tests

Delete your boilerplate today.

Free and open source under the MIT license.

dotnet add package Blazor.AutoGen --prerelease