Skip to content

Adds a Blazor WebAssembly (.NET 10) + Motoko Hello World template.#1359

Open
mitnick2012 wants to merge 1 commit into
dfinity:masterfrom
mitnick2012:master
Open

Adds a Blazor WebAssembly (.NET 10) + Motoko Hello World template.#1359
mitnick2012 wants to merge 1 commit into
dfinity:masterfrom
mitnick2012:master

Conversation

@mitnick2012

Copy link
Copy Markdown

Overview
The icp-cli templates library has no support for .NET/C# developers who want to
build on ICP using Blazor WebAssembly. This template fills that gap by providing
a working starter project that combines Blazor WASM (.NET 10) on the frontend with
a Motoko canister on the backend, using icp-cli for deployment. Without this template,
.NET developers face undocumented pitfalls that make getting started unnecessarily
difficult.

Requirements

  • Blazor WASM frontend that successfully calls a Motoko backend canister
  • Uses icp-cli with canister.yaml configuration (not dfx)
  • Works on local network and mainnet
  • Documents all known gotchas specific to Blazor + ICP
  • No JS interop race conditions between @dfinity/agent and Blazor runtime
  • Canister ID discovery via ic_env cookie without hardcoding

Considered Solutions

  1. ES module script (type="module") for @dfinity/agent — rejected due to browser
    deferral behavior causing a race condition where Blazor attempts JS interop before
    the module is ready, silently breaking button events.
  2. Webpack bundle loaded with defer — selected. Compiles @dfinity/agent into a
    single plain JS file exposed as window.IcpAgent. The defer attribute guarantees
    script execution order before DOMContentLoaded, so the global is always available
    when Blazor makes its first JS interop call.

Recommended Solution
Webpack + defer loading pattern, modeled after the existing Dfinity.Blazor
community library. This is the only approach that reliably solves the JS interop
race condition without adding complexity to the Blazor startup sequence. It also
bundles @dfinity/agent locally (no CDN dependency), pins the version in package.json,
and produces a single minified file that the asset canister can certify correctly.

Considerations

  • Security: No impact. The template follows the same trust model as other icp-cli
    templates — no private keys, no hardcoded canister IDs.
  • Performance: The webpack bundle adds ~271KB (uncompressed) to the frontend assets.
    This is negligible compared to the Blazor WASM runtime (~5MB+). Brotli compression
    via the asset canister reduces the bundle to ~80KB on the wire.
  • Users: Purely additive. Existing templates are unaffected. .NET developers gain
    a working starting point without having to discover undocumented pitfalls.
  • Breaking changes: None.
  • Maintenance: Low. The template depends on @dfinity/agent and the @dfinity/motoko
    recipe — both of which are maintained by DFINITY. The .NET 10 LTS support window
    runs until November 2028, so no forced upgrade in

@mitnick2012 mitnick2012 requested a review from a team as a code owner June 9, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant