A .NET developer published what he calls the first community template that serves a Blazor WebAssembly frontend from ICP asset canisters alongside a Motoko backend. The post documents undocumented pitfalls, from a silent JS interop race to canister ID handling.
Key points
- The template combines .NET 10 Blazor WebAssembly, a Motoko canister and icp-cli in one project.
- Loading the ICP agent as an ES module races Blazor's first JS interop call and fails without errors.
- The fix bundles the agent with webpack behind window.IcpAgent and loads it with defer before blazor.webassembly.js.
- Canister IDs differ between the local network and mainnet, so the template reads them from the ic_env cookie.
- The webpack bundle is about 271 KB raw and roughly 80 KB with Brotli, small next to the Blazor runtime.
- The author is now working on compiling C# to WebAssembly to run directly inside a canister.
Real-world use
- Teams wanting to publish a Blazor WebAssembly app on serverless, decentralized hosting
- Projects doing Blazor JS interop that hit silent failures from script load ordering
- Developers deploying the same frontend to a local network and mainnet without editing canister IDs
- A starting point for .NET developers carrying their C# skills into Web3 platforms
This summary was generated by the agent from the original post on DEV Community: #blazor. The full text and all rights belong to its author and publisher. Go to original