question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor WASM: Decouple EntrypointInvoker and DefaultWebAssemblyJSRuntime from WebAssembly.dll

See original GitHub issue

By decoupling and/or simply exposing these 2 internal classes, we can enable more aggressive trimming in minimalistic WASM apps. This results in a reduction of 15+ dll dependencies that WebAssembly.dll brings with it, improving page load performance for minimalistic wasm applications.

Summary

Currently (in version 5.0.1), one must either exclude Microsoft.AspNetCore.Components.WebAssembly.dll from linking or at least reference the Microsoft.AspNetCore.Components.WebAssembly.Hosting class to produce a viable build that executes and interops with Javascript.

Motivation and goals

Microsoft.AspNetCore.Components.WebAssembly.dll is currently a monolith that

  • is required to successfully produce a build because it produces JS files.
  • is explicitly required by blazor.webassembly.js
  • contains the mostly standalone classes EntrypointInvoker and DefaultWebAssemblyJSRuntime, which are required for JS interop
  • contains additional services and dependencies to support the full Blazor framework but that are not relevant for a simple Hello World or minimalistic application.

This is a relatively simple change that would help break the WebAssembly.dll monolith.

In scope

  • This only concerns trimming of WebAssembly.dll
  • A simple Hello World console application (or equivalent) should not result in the loading of Microsoft.Extensions.* and Microsoft.AspNetCore.* dlls or other unnecessary dlls.

Out of scope

  • This does not concern trimming of other Blazor or .Net dependencies.

Risks / unknowns

This change does not break functionality. Some documentation for proper use would be needed.

Examples

A project file to support the minimalistic build would look like this.

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <PublishTrimmed>true</PublishTrimmed>
    <TrimMode>link</TrimMode>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.1" />
  </ItemGroup>
  <ItemGroup>
    <TrimmerRootAssembly Include="[NEW MINIMAL DEPENDENCY]" />
  </ItemGroup>
</Project>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
captainsafiacommented, Jan 12, 2021

@ejhg Thanks for being considerate!

@danroth27 Ping in case you want to continue digging into feasibility/interest for this.

0reactions
ejhgcommented, Jan 12, 2021

@captainsafia @javiercn Thank you for giving consideration to this proposal. I don’t want to increase your backlog size. I can write my own interop layer anyways, so this is not a blocker for me. I just thought this would be good design feedback to give y’all.

I’ll close this ticket so it doesn’t create unnecessary backlog. Thanks again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deployment layout for ASP.NET Core Blazor ...
Learn how to enable Blazor WebAssembly deployments in environments that block the download and execution of dynamic-link library (DLL) ...
Read more >
dotnet application refusing to serve .dll files in wwwroot ...
I found the solution. The reason dotnet was refusing to serve the .dll files needed in Blazor was that they have an unknown...
Read more >
Blazor Client (WASM) decompiles to C#? : r/ ...
Blazor WebAssembly is running .NET DLL's in your browser. Decompiling these DLL's is just as easy as with any other .NET DLL. The...
Read more >
WebAssembly and Blazor: A Decades Old Problem Solved
The mono.js JavaScript dynamically loads mono.wasm and begins running .NET in the browser. The remaining loads are the actual DLL files that ...
Read more >
Blazor WASM local dlls
I have a very specific use case, where the Blazor WASM app is supposed to lazy load a dll from the server (this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found