Skip to content

Unable to render a component from a library using the WebAssembly render mode #50609

@danroth27

Description

@danroth27

Repro steps:

  • Install .NET 8 RC1
  • Create a Blazor Web App with interactive WebAssembly rendering enabled
  • Remove Components/Pages/Counter.razor from the server project
  • In the client project update Pages/Counter to remove the @page directive and the render mode
  • In the server project add a Counter to the Home page with @rendermode="@RenderMode.WebAssembly": <BlazorApp1.Client.Pages.Counter @rendermode="@RenderMode.WebAssembly" />`
  • Run the app and verify that the Counter works correctly on the home page
  • Now add a Razor Class Library (RCL) to the solution
  • Add a project reference from the Client project to the RCL
  • Move the Counter component from the Client project to the RCL
  • Update the Home page to use the Counter component from the RCL, still with the WebAssembly render model: <RazorClassLibrary1.Counter @rendermode="@RenderMode.WebAssembly" />
  • Run the app again

Expected result: Counter still works on the home page
Actual result:

The Counter prerenders but then I get this error in the browser dev console:

blazor.web.js:1  Uncaught (in promise) Error: System.InvalidOperationException: Root component type 'RazorClassLibrary1.Counter' could not be found in the assembly 'RazorClassLibrary1'.
   at Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer.<UpdateRootComponents>g__AddRootComponent|8_0(RootComponentOperation operation)
   at Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer.UpdateRootComponents(String operationsJson)
   at Microsoft.AspNetCore.Components.RenderTree.WebRenderer.WebRendererInteropMethods.UpdateRootComponents(String operationsJson)
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
--- End of stack trace from previous location ---
   at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(JSRuntime jsRuntime, DotNetInvocationInfo& callInfo, IDotNetObjectReference objectReference, String argsJson)
   at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, String argsJson)
    at v.endInvokeDotNetFromJS (https://localhost:7015/_framework/blazor.web.js:1:3502)
    at Object.Mr [as endInvokeDotNetFromJS] (https://localhost:7015/_framework/blazor.web.js:1:146428)
    at https://localhost:7015/_framework/dotnet.runtime.8.0.0-rc.1.23419.4.lgn8dfjh3t.js:3:177563
    at El (https://localhost:7015/_framework/dotnet.runtime.8.0.0-rc.1.23419.4.lgn8dfjh3t.js:3:178397)
    at wasm://wasm/00b1e17a:wasm-function[350]:0x1faed
    at wasm://wasm/00b1e17a:wasm-function[246]:0x1bf8a
    at wasm://wasm/00b1e17a:wasm-function[239]:0xf171
    at wasm://wasm/00b1e17a:wasm-function[273]:0x1d1af
    at wasm://wasm/00b1e17a:wasm-function[3183]:0xe7ef0
    at wasm://wasm/00b1e17a:wasm-function[2504]:0xbdcfe

Workaround: Create a wrapper component in the client project around the Counter component from the RCL and use the wrapper component from the Home page instead.

https://github.com/danroth27/BlazorIssue50609

Metadata

Metadata

Assignees

Labels

✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.question

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions