InteractiveWebAssemblyRenderMode not working when navigate to shared library page

570 Views Asked by At

I am using Blazor Web App template introduced in .Net Core 8.0

I want to render Blazor pages as InteractiveWebAssemblyRenderMode that are shared between different projects. So I created a shared Razor class library.

It works fine when I use InteractiveAutoRenderMode or move the .razor file to .Client project, but as soon as I move the .razor file to shared project it starts giving me error. Root component type 'Frontend.Interface.Pages.Job' could not be found in the assembly 'Frontend.Interface.Pages'.

As long as I copy all the pages into the *.Client project, everything works fine. (Server rendering and Client rendering) How can I tell the *.Client project that all pages are stored in a different project? Is there anything like this AdditionalAssemblies=new[] { typeof(MyPage).Assembly}? Or is it not possible at the moment?

1

There are 1 best solutions below

0
On BEST ANSWER

I found a work around of my problem, it was because of tree shaking, while trying to use a WebAssemblyRenderMode content from a razor class library project.

I had to write a reference of my WebAssembly component type in my client Main method before calling RunAsyc.

var builder = WebAssemblyHostBuilder.CreateDefault(args);

var type = typeof(WebAssemblyRenderedPage);

//Register your client side services here

await builder.Build().RunAsync();

https://github.com/dotnet/aspnetcore/issues/26601#issuecomment-1125036157