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.23k stars 9.95k forks source link

Blazor cannot find entrypoint when a library from another folder is referenced. #30594

Closed Cryru closed 9 months ago

Cryru commented 3 years ago

Describe the bug

If you have a Blazor executable project reference a library-type project from the same solution, but located in another folder on the filesystem, upon the browser opening you will see an error in the console and your program wont start.

To Reproduce

https://github.com/Cryru/BlazorBugRepro Here's a reproducing repo. Steps to reproduce:

  1. Open up the solution in FolderTwo
  2. Make sure the "BlazorExecutable" project references "BlazorLibrary"
  3. Start the project
  4. You will see the exception in the browser's dev tools window and none of your code will be executed.

Additional steps:

  1. Remove the reference to "BlazorLibrary" and add a reference to "BlazorLibrarySameFolder"
    • This project is an identical copy-paste, with only the name changed.
  2. Start the project
  3. The application starts and you're greeted with a rendered Razor page.

Kind of weird it only works in the second case, isn't it?

Exceptions (if any)

System.NullReferenceException: Object reference not set to an instance of an object.
blazor.webassembly.js:1    at Microsoft.AspNetCore.Components.WebAssembly.Hosting.EntrypointInvoker.FindUnderlyingEntrypoint(Assembly assembly)
blazor.webassembly.js:1    at Microsoft.AspNetCore.Components.WebAssembly.Hosting.EntrypointInvoker.InvokeEntrypoint(String assemblyName, String[] args)

Further technical details

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

Host (useful for support): Version: 5.0.0 Commit: cf258a14b7

.NET SDKs installed: 2.1.600 [C:\Program Files\dotnet\sdk] 2.1.601 [C:\Program Files\dotnet\sdk] 2.1.700-preview-009618 [C:\Program Files\dotnet\sdk] 2.1.800-preview-009696 [C:\Program Files\dotnet\sdk] 2.2.200 [C:\Program Files\dotnet\sdk] 2.2.201 [C:\Program Files\dotnet\sdk] 2.2.300-preview-010067 [C:\Program Files\dotnet\sdk] 2.2.400-preview-010219 [C:\Program Files\dotnet\sdk] 3.0.100-preview-010184 [C:\Program Files\dotnet\sdk] 5.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0-preview-19075-0444 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0-preview-27324-5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0-preview-27325-3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]


- IDE: VS 2019 16.8
mkArtakMSFT commented 3 years ago

Thanks for contacting us. We plan to improve experience in this area and that work is tracked as part of several existing issues (which may seem irrelevant at first so won't link them here). For now we recommend not to name the entry-point classes the same to avoid this issue.

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.

Cryru commented 3 years ago

Thanks for the reply @mkArtakMSFT but I'm not sure which entry point classes you are referring to? The BlazorLibrary projects do not have entry points as they are marked as libraries (and executing them does rightfully present the same exception). I updated the reproducible example with a renamed entrypoint class ("Program" to "ExecutableEntryPoint") which still reproduces the issue.

Cryru commented 3 years ago

It seems it works when hosting the compiled result in ./wwwroot with another http server, which leads me to believe the problem is with the way Visual Studio launches the project.

mkArtakMSFT commented 9 months ago

This area has changed significantly, and this error is no longer applicable. Nor we had seen more customers hitting this so closing at this point.