Lindstrøm
Lindstrøm

Reputation: 456

Razor Pages only render when using RuntimeCompilation .NET 8 Preview 6

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

Upvotes: 2

Views: 701

Answers (1)

Guru Stron
Guru Stron

Reputation: 143113

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.

Upvotes: 1

Related Questions