dotnet / dotnet/aspnetcore

Assembly lazy load in a Blazor WebProject with rendermode InteractiveWebAssembly(Page/component)

Open
#57,117 1 comment 0 reactions 0 assignees View on GitHub
area-blazor enhancement feature-blazor-lazy-loading Pillar: Complete Blazor Web Priority:1 triaged
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

Hello,

following this example:
https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-lazy-load-assemblies?view=aspnetcore-8.0

I was able to use the assembly lazy load in a Blazor WebAssembly application in net8, now I am trying to implement the same in a Blazor Web Application with `rendermode InteractiveWebAssembly`.
The start solution has two project, the application project and the .Client project. I added a `RCL library (LazyLibrary)` to the solution, inside the `RCL` I added a page component with `@rendermode RenderMode.InteractiveWebAssembly`. I added to .Client project a reference to `RCL` and I added

```



```

to application project file, but I can not navigate to the page in the `RCL`.
This are the key points I understood:
The classic Blazor WebAssembly project has `Router.AdditionalAssemblies `empty when it starts. The Blazor webApp seems always ignore `Router.AdditionalAssemblies` but use the new extension method `app.MapRazorComponents().AddAdditionalAssemblies(...)`, so to reproduce the same I didnt add the `LazyLibrary` to `AddAdditionalAssemblies`. In this case, when I run the applicazion and I try to navigate to the page in the `RCL`, I get a `404` and `OnNavigateAsync` not fire. So I tried to add the `LazyLibrary `to `AddAdditionalAssemblies` in` programs.cs`. In this way, when I navigate to the page in the RCL, the body of the page is rendered, `OnNavigateAsync` fire, but I get the error:

![image](https://github.com/user-attachments/assets/60d0545b-411f-4b82-9639-3f06b279c4bb)

If i first navigate to counter(that download the application) and after I navigate to the page in the RCL I get this error

![image](https://github.com/user-attachments/assets/e7e64e3c-82cf-4558-98fb-605f75042abe)

Maybe because the asemblies added (in `OnNavigateAsync`) to `Router.AdditionalAssemblies` is ignored.

So is it possible implement Assembly lazy load in a Blazor Web project with `rendermode InteractiveWebAssembly`?

If it is useful the simply project I am using is at :
https://github.com/GLuca74/BlazorApp2

Thanks

### Expected Behavior

Implement Assembly lazy load

### Steps To Reproduce

https://github.com/GLuca74/BlazorApp2

### Exceptions (if any)

_No response_

### .NET Version

8.0.107

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.