1

I experience some strange behaviour. When using the standard ASP .NET 8 (or .NET 7) Web App template, the template does not render (or the route is not recognized) unless I use RuntimeCompilation - and I don't want to.

In the browser I'm presented with the standard 404 error page in Chrome.

The middleware pipeline seems fine

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);    
// Working
// -----------------------------------------------
builder.Services.AddRazorPages().AddRazorRuntimeCompilation();

// Not Working
// -----------------------------------------------
builder.Services.AddRazorPages();

WebApplication app = builder.Build();

if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapRazorPages();

app.Run();

I'm using .NET 8 preview 6

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Lindstrøm
  • 396
  • 2
  • 16
  • 1
    Can you please provide some [mre] with routes tried which return 404 when should not? – Guru Stron Jul 18 '23 at 23:19
  • It applies when I create a new web app using the template in visual studio 2022 17.6.5 I can only view i.e. https://localhost:7060/index if I use RunTime compilation. I wonder if there is some kind of setting in VS I have missed. – Lindstrøm Jul 19 '23 at 07:22
  • I have investigated the issue further. It only applies when building and running the project from VS 2022. If I build and run the project from PowerShell everything is fine. – Lindstrøm Jul 19 '23 at 07:32
  • 1
    Was not able to repro. Have you installed and run the project from latest preview version (for .NET 8)? – Guru Stron Jul 21 '23 at 06:45
  • 1
    Also you can try modifying the `launchSettings.json` and adding `ASPNETCORE_HOSTINGSTARTUPASSEMBLIES` environment variable with `Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation` value there. – Guru Stron Jul 21 '23 at 06:47
  • Yes, I working on the latest preview version, and I happens also on a clean project template. I'm suspect is must be some kind of local setting in VS2022 – Lindstrøm Jul 21 '23 at 10:00
  • 1
    Do you have the latest VS preview too? – Guru Stron Jul 21 '23 at 10:01
  • 1
    Thx. This did the trick!!. I was using VS2022 17.6.5 – Lindstrøm Jul 21 '23 at 11:08
  • Was glad to help! Added last two comments as an answer. – Guru Stron Jul 21 '23 at 11:16

1 Answers1

1

Was not able to repro but as workaround you can try modifing launchSettings.json by adding ASPNETCORE_HOSTINGSTARTUPASSEMBLIES environment variable with Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation for corresponding run profile (a bit more info about this can be found in this answer).

Also be sure to use the latest VS 2022 preview version (17.7 Preview 4 ATM) to work with the latest .NET 8 preview.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132