Share via

.NET 10 Blazor WebAssembly – Calling C# from JavaScript no longer works (JSInvokable / JSExport / createDotNetRuntime)

RC 0 Reputation points
2026-02-05T14:30:23.39+00:00

I’m building an Ionic / Angular Android application that needs to execute C# code from DLLs via WebAssembly.

Working setup (.NET 9)

With .NET 9, everything works fine using this approach:

  • Blazor WebAssembly project
  • C# methods decorated with [JSInvokable]
  • Build the project → get the /framework folder
  • Copy /framework into the Angular app
  • Call C# from JavaScript using:
  • DotNet.invokeMethodAsync("MyAssembly", "MyMethod")

This works perfectly.

Problem after upgrading to .NET 10

After upgrading the C# projects to .NET 10, the whole setup breaks.

It looks like Blazor WebAssembly / JS interop internals have changed significantly and I can no longer call C# methods from my Angular app.

What I tried

  1. [JSInvokable] (Blazor-style interop)

No longer works

DotNet.invokeMethodAsync fails

The runtime initialization seems different / missing

2. [JSExport] (Native WASM interop)

I tried the “new” recommended approach:

`dotnet publish -c Release -r browser-wasm`

This produces .wasm and .js files

[JSExport] methods are compiled correctly

But when calling it from Angular, I get:

`createDotNetRuntime is not defined`

It looks like .NET 10 no longer exposes a simple JS bootstrap API usable outside of the official Blazor hosting model.

Current conclusion

It seems that with .NET 10, Microsoft no longer supports:

  • Reusing Blazor WebAssembly output inside non-Blazor apps
  • Calling C# code from JavaScript without fully adopting the new runtime model
  • Downgrading to .NET 9 is not a viable long-term solution.

What I’m looking for

Is there a supported way in .NET 10 to:

  • Load the .NET WASM runtime manually?
  • Call C# methods from JavaScript in a non-Blazor app?
  • Is there a replacement for DotNet.invokeMethodAsync?
  • Any official or community workaround for using .NET WASM as a library?

Any guidance, examples, or confirmation that this is no longer supported would be greatly appreciated.

Thanks!

Developer technologies | .NET | Blazor
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Le (WICLOUD CORPORATION) 11,080 Reputation points Microsoft External Staff Moderator
    2026-02-06T08:58:44.4333333+00:00

    Hello @RC ,

    With .NET 9, everything works fine using this approach

    I get what you're trying to do, but this approach was never officially supported. Blazor WebAssembly is meant to be a full hosting model, not a library.

    Also, this change is probably the main reason for the issue: https://learn.microsoft.com/en-us/aspnet/core/migration/90-to-100?view=aspnetcore-10.0#boot-configuration-file-inlined.

    blazor.boot.json is no longer used in .NET 10 Blazor WebAssembly apps, which makes it impossible to load Blazor WebAssembly as a library in non-Blazor apps. You could try to reverse-engineer the dotnet.js bootstrapping code to recreate the old behavior, but that would be quite a bit of work and probably not worth it.

    If you want to use .NET inside non-Blazor JS apps, you should look into the .NET for WebAssembly browser apps support instead: https://github.com/dotnet/runtime/blob/main/src/mono/wasm/features.md

    While this is a non-Microsoft site, it is the official Github repository for the .NET runtime.

    and the documentation here https://learn.microsoft.com/en-us/aspnet/core/client-side/dotnet-interop/wasm-browser-app?view=aspnetcore-10.0.

    I hope this clarifies.

    1 person found this answer helpful.
    0 comments No comments

  2. Q&A Assist
    2026-02-05T14:30:42.23+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    In .NET 10, the interop model for Blazor WebAssembly has indeed changed, which affects how you can call C# methods from JavaScript in non-Blazor applications. Here are some points to consider based on the current context:

    1. JS Interop Changes: The traditional [JSInvokable] approach you used in .NET 9 is still valid but may require adjustments due to changes in the runtime initialization. Ensure that your project is correctly set up to use the new interop model.
    2. Using [JSExport]: This is the recommended approach for calling C# from JavaScript in .NET 10. However, if you are encountering issues like createDotNetRuntime is not defined, it indicates that the required runtime setup is not being executed properly. You may need to ensure that the JavaScript files generated during the publish process are correctly included and initialized in your Angular application.
    3. Loading the .NET WASM Runtime: While the new model may not expose a simple bootstrap API for non-Blazor apps, you can still load the runtime manually. You will need to include the generated JavaScript and WASM files in your Angular project and ensure that the runtime is initialized correctly before making any calls to C# methods.
    4. Calling C# Methods: For calling C# methods from JavaScript, you will use the [JSExport] methods, but you must ensure that the runtime is initialized correctly. The DotNet.invokeMethodAsync method is part of the Blazor hosting model, and if you are not using Blazor, you will need to adapt your approach to use the new interop methods available with [JSExport].
    5. Workarounds: If you find that the new model does not meet your needs, consider looking into community solutions or examples that demonstrate how to integrate .NET WebAssembly into non-Blazor applications. The official documentation may also provide insights into best practices for this scenario.

    In summary, while there are significant changes in .NET 10, it is still possible to call C# methods from JavaScript, but it requires adapting to the new interop model and ensuring proper runtime initialization.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.