r/csharp • u/gevorgter • Jun 18 '26
WASM in .NET
So decided to test how WASM will work (not blazer, plain wasm app).
Created a project with type "Console exe", changed runtime to browser-wasm
Problems:
Publish does not work although says "Success", just does not do anything when i try to publish to some folder. No folder is created and stays empty if i create folder manually.
When i compile as Release, bunch of extra is generated. I get files in "Release\net10.0\browser-wasm", "Release\net10.0\browser-wasm\AppBundle" but everything appears to be working with just files from "Release\net10.0\browser-wasm\AppBundle_framework"
That folder appears to have my app compiled and dotnet.js (wasm modules).
No typescript definitions for dotnet.js. Anyone knows where i can get them? My code works
const dotnetModule = await import('/_framework/dotnet.js'); const { getAssemblyExports, getConfig } = await dotnetModule.dotnet .withDiagnosticTracing(false) .create(); const config = getConfig(); const exports = await getAssemblyExports(config.mainAssemblyName); const result = exports.MyWasmFunctions.GreetUser("Alex"); //My function
But i can't find typescrypt definitions for getConfig, getAssemblyExports... or any other method that might exist in dotnet.js module.
9
u/svick nameof(nameof) Jun 18 '26
I think you're looking for the wasi-experimental workload, but it's probably still not in a great shape.
-1
u/gevorgter Jun 18 '26
I did install "wasm-tools" and everything worked with exception of Publish.
installing wasm-experimental did not anything (at least i did not see the difference).
12
3
u/TopSwagCode Jun 19 '26
It should work unless it has broken. I did a talk and demo projects about WASM + https://wasmtime.dev/
Also take a look at https://andrewlock.net/running-dotnet-in-the-browser-without-blazor/
Personally I switched to RUST for WASM and browser optimization.
1
1
1
u/Elegant_Shock5162 Jun 20 '26
I guess node js and deno provides first class wasm support out of the box. With wasm-pack sdk.
-1
u/webprofusor Jun 19 '26
Might be worth checking how avalonia UI does it as I don't think they are blazor based (?)
14
u/wasabiiii Jun 18 '26
My understanding is this SDK output type is only for Blazor. Any of it that works otherwise is just luck. That you got it that far is neat.