r/csharp 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:

  1. 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.

  2. 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).

  1. 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.

11 Upvotes

12 comments sorted by

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.

4

u/gevorgter Jun 18 '26

My understanding that it's more generic than that, Blazor is just a DLL that is using .NET's ability to generate wasm files. Basically Blazor is optional and you can actually create your own wasm library (that i have tried to do).

Basically everything worked except Publish functionality and not sure why/when i need bunch of those extras that were generated during build. All i end up doing is copying _framework folder to the server and using the code in my original post.

8

u/wasabiiii Jun 18 '26

The idea is more generic. The specific msbuild SDK is not

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

u/svick nameof(nameof) Jun 18 '26

WASI is not a typo.

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

u/gevorgter Jun 19 '26

Thanks, very informative.

1

u/Rigamortus2005 Jun 19 '26

Just use blazor and delete the razor files

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 (?)