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.16k stars 9.92k forks source link

Converting existing Blazor Hosted project to Blazor Web App resulting in missing index.html #54313

Closed manuelelucchi closed 6 months ago

manuelelucchi commented 6 months ago

Is there an existing issue for this?

Describe the bug

I have this existing Blazor Hosted project (Client + Shared + Server) that I migrated without problems to .NET 8. I then tried experimenting with the new Interactivity features and after following the documentation, when I start the project and navigate to the entrypoint it gives me a 404 with the following log

info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/1.1 GET http://localhost/ - - -
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/1.1 GET http://localhost/ - 404 0 - 10.0613ms
info: Microsoft.AspNetCore.Hosting.Diagnostics[16]
      Request reached the end of the middleware pipeline without being handled by application code. Request path: GET http://localhost/, Response status code: 404

Like it's missing the generated index.html. I tried publishing the project and the index.html seems correctly generated from the App.razor This behavior doesn't happen in another project I converted in the same way (below the passages).

Expected Behavior

The endpoint should hit the index.html correctly

Steps To Reproduce

Starting from an existing Blazor Hosted project converted to .NET 8

(I need `prerender: false` since I use local storage)
- Deleted the index.html
- Deleted `builder.RootComponents.Add<App>("#app");` from the Program.cs in the Client
- In the Server project, I added the following lines
```csharp
builder.Services.AddRazorComponents()
    .AddInteractiveServerComponents()
    .AddInteractiveWebAssemblyComponents();

and before app.MapRazorPages()

app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode()
    .AddInteractiveWebAssemblyRenderMode()
    .AddAdditionalAssemblies(typeof(_Imports).Assembly);

Exceptions (if any)

No response

.NET Version

8.0.200

Anything else?

.NET SDK: Version: 8.0.200 Commit: 438cab6a9d Workload version: 8.0.200-manifests.5638171e

Ambiente di runtime: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.200\

Carichi di lavoro .NET installati: [ios] Origine dell'installazione: SDK 8.0.200, VS 17.9.34616.47 Versioni del manifesto: 17.2.8022/8.0.100 Percorso del manifesto: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.ios\17.2.8022\WorkloadManifest.json Tipo di installazione: FileBased

[wasm-tools] Origine dell'installazione: SDK 8.0.200 Versioni del manifesto: 8.0.2/8.0.100 Percorso del manifesto: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.workload.mono.toolchain.current\8.0.2\WorkloadManifest.json Tipo di installazione: FileBased

[maui-windows] Origine dell'installazione: VS 17.9.34616.47 Versioni del manifesto: 8.0.6/8.0.100 Percorso del manifesto: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.6\WorkloadManifest.json Tipo di installazione: FileBased

[maccatalyst] Origine dell'installazione: VS 17.9.34616.47 Versioni del manifesto: 17.2.8022/8.0.100 Percorso del manifesto: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maccatalyst\17.2.8022\WorkloadManifest.json Tipo di installazione: FileBased

[android] Origine dell'installazione: VS 17.9.34616.47 Versioni del manifesto: 34.0.79/8.0.100 Percorso del manifesto: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.android\34.0.79\WorkloadManifest.json Tipo di installazione: FileBased

Host: Version: 8.0.2 Architecture: x64 Commit: 1381d5ebd2

.NET SDKs installed: 8.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

manuelelucchi commented 6 months ago

I'm definitely not able to reproduce. I tried to create a .NET 7 Blazor Hosted project, converted to .NET 8 Web App and it works. I have no clue of what could be the difference, the steps I pointed above are the same for both my projects (and in one they work) and the repro.

I tried publishing both my projects and noticed they both don't have the index.html in the wwwroot1 folder, so I assume theMapRazorComponentsregisters a middleware that generates theindex.htmlper requests based on theApp.razor` and for some reasons on a single project out of three it doesn't work.

There surely something wrong on my part but the question is what? Is there something that could interfere with the Middleware? My configuration (in Development env) is as follows

app.UseDeveloperExceptionPage();
app.UseWebAssemblyDebugging();

app.UseMigrationsEndPoint();
app.UseSwagger();
app.UseSwaggerUI(options =>
{
    // Stuff
});

app.UseBlazorFrameworkFiles();
app.UseStaticFiles();

app.UseRouting();
app.UseAntiforgery();

app.UseRequestLocalization(options =>
{
    // Stuff
});

app.UseAuthentication();
app.UseAuthorization();

app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode()
    .AddInteractiveWebAssemblyRenderMode()
    .AddAdditionalAssemblies(typeof(_Imports).Assembly);

app.MapRazorPages();
app.MapControllers();

app.Run();

The rest is as I specified above

mkArtakMSFT commented 6 months ago

Thanks @manuelelucchi. This seems to be an issue specific to your project / migration. For these situations we recommend you post a question to the StackOverflow forum to get help faster.

aledamen commented 2 months ago

Hello, could you fix this issue? I have the same problem.

Thanks!