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.38k stars 10k forks source link

Blazor Server Not rendering components from the "Shared/" folder when using a Startup type located in a different project #33788

Closed asser-dk closed 10 months ago

asser-dk commented 3 years ago

Describe the bug

I'm unsure if this is a proper bug or if it's a case of me "holding it wrong" but here goes:

A bit of context: 99 out of 100 of my services have the exact same Startup.cs setup so in order to make it easier to propagate changes I moved the Startup type to a shared libary/package so I just had to update the package reference going forward. (It sounded smart back then at least.) Now I am trying to enable Blazor Server and I noticed this issue/bug.

Issue/Bug: In a Blazor Server project, if the Startup type is located in a different project then components from the Shared/ folder are not rendered. Even when the assembly (which contains the pages and components) is added to the MVC ApplicationParts and Razor Runtime Compilation FileProviders.

The application produce no exception or errors in either the browser console or the regular debug/console output. The application is loading, you can navigate to the individual pages directly by changing the url in the browser, and the static files like style sheets are served correctly, however; the Layout and NavMenu components from the Shared/ folder are not rendered.

I enabled debug logging for Microsoft.AspNetCore and it looks like it picks up the components just fine. No errors or exceptions are generated.

To Reproduce

  1. Create a blazor server app using dotnet new blazorserver
  2. Create a class library
  3. Add Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation as a package reference for the library project
  4. Move the Startup type to the library project
  5. Reference the new class library from the blazor app
  6. Ensure that .UseStartup<Startup>() points to the type from the library project
  7. Modify the content of ConfigureServices() in the Startup type like so:
    
    var assembly = Assembly.GetEntryAssembly(); // Should point to the original blazor server app

services .AddRazorPages() .AddApplicationPart(assembly) .AddRazorRuntimeCompilation(options => options.FileProviders.Add(new EmbeddedFileProvider(assembly)));

services.AddServerSideBlazor();

8. Run the blazor app and notice that the navigation bar and layout in general is missing

Repo: https://github.com/asser-dk/BlazorServerSideWithSharedStartup
See TodoList/Program.cs and switch between "WorkingStartup" and "BrokenStartup"

### Exceptions (if any)
No exceptions are produced, and no errors show up in the log output

### Further technical details

I'm running the application from the command line. I tried both on WSL and in a regular CMD prompt.

dotnet --info (WSL):

.NET SDK (reflecting any global.json): Version: 5.0.301 Commit: cc8c0abb32

Runtime Environment: OS Name: ubuntu OS Version: 18.04 OS Platform: Linux RID: ubuntu.18.04-x64 Base Path: /usr/share/dotnet/sdk/5.0.301/

Host (useful for support): Version: 5.0.7 Commit: 556582d964

.NET SDKs installed: 3.1.410 [/usr/share/dotnet/sdk] 5.0.301 [/usr/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.16 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.7 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.16 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.7 [/usr/share/dotnet/shared/Microsoft.NETCore.App]


dotnet --info (cmd)

.NET SDK (reflecting any global.json): Version: 5.0.301 Commit: ef17233f86

Runtime Environment: OS Name: Windows OS Version: 10.0.19043 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.301\

Host (useful for support): Version: 5.0.7 Commit: 556582d964

.NET SDKs installed: 2.2.402 [C:\Program Files\dotnet\sdk] 3.0.100 [C:\Program Files\dotnet\sdk] 3.1.402 [C:\Program Files\dotnet\sdk] 3.1.410 [C:\Program Files\dotnet\sdk] 5.0.100 [C:\Program Files\dotnet\sdk] 5.0.204 [C:\Program Files\dotnet\sdk] 5.0.301 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

ghost commented 3 years ago

Thanks for contacting us.

We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

ghost commented 3 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

mkArtakMSFT commented 10 months ago

Hi. Thanks for contacting us. We're closing this issue as there was not much community interest in this ask for quite a while now. You can learn more about our triage process and how we handle issues by reading our Triage Process writeup.