Can I omit .NET Core references of Blazor WASM?

Matěj Rada 40 Reputation points
2024-02-19T17:10:23.62+00:00

When publishing standard Blazor WASM which would be provided via Blazor server, how can I omit all references currently already available on my MAUI client? As I hope to reduce size of downloaded WASM when I am using .NET emulating within BlazorWebView, not standard browser. I want to achieve online available WASM modules by purchase available for MAUI client already containing the majority of necessary references.

Developer technologies | .NET | Blazor
Developer technologies | .NET | .NET MAUI
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,926 Reputation points Volunteer Moderator
    2024-02-20T16:55:08.6233333+00:00

    This won’t work. when hosting Blazor, Maui uses the webviews WASM support, so the WASM dlls are all required. Normally the dlls are hosted as Maui asset files, so they are loaded locally.

    Even if the Maui app and the Blazor app use the same .net dll, there two versions, one compiled to native os (for Maui) and one compiled to WASM (which is a virtual machine with its own instruct set based on asm.js)


  2. Rada Matěj 200 Reputation points
    2024-02-23T09:02:28.6433333+00:00

    Finally, it is working!

    https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/call-dotnet-from-javascript?view=aspnetcore-8.0#create-javascript-object-and-data-references-to-pass-to-net

    Answer is very easy. I can deploy WASM with conditional references, so they will be omitted in deployed WASM. I can leak .NET object from WASM into JS. JS can leak unmarshalled object into MAUI client. MAUI client can provide any of its loaded assembly as a byte array for unmarshalled WASM object. WASM can use those bytes to dynamically load any omitted assembly. That is how to shrank WASM when I have direct control on client side to still provide working WASM at the end.

    0 comments No comments

Your answer

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