dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.4k stars 10k forks source link

.Net 9 Blazor Server doesn't find components in interactive mode #58625

Open Julien-Marpault opened 2 days ago

Julien-Marpault commented 2 days ago

Is there an existing issue for this?

Describe the bug

I have a solution with a hierarchy of projects:

Store | Presentation | Application |_Domain etc.

My App.razor and Routes.razor are in the Store project. My other pages are in the presentation project.

I added AdditionalAssemblies:

app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode()
    .AddAdditionalAssemblies(typeof(Presentation.Pages.Index).Assembly);

If I try to use InteractiveServer on Routes component I get a Not found error, the app can't find the '/' route. The same issue occurs when using this mode on HeadOutlet component.

If I don't use InteractiveServer render mode it works fine.

So I tried to apply InteractiveServer to my Layout because I have some interactivity in my layout. I get this error:

InvalidOperationException: Cannot pass the parameter 'Body' to component 'MainLayout' with rendermode 'InteractiveServerRenderMode'. This is because the parameter is of the delegate type 'Microsoft.AspNetCore.Components.RenderFragment', which is arbitrary code and cannot be serialized.

Last try, I moved my pages to Store project leaving other components to Presentation. It works fine, but it's an issue to not be able to put my pages in a separate library.

javiercn commented 2 days ago

@Julien-Marpault thanks for contacting us.

You also need to add the additional assemblies to the Router Component.

dotnet-policy-service[bot] commented 2 days ago

Hi @Julien-Marpault. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.