I have ported my application from asp.net core 5.0 to asp.net core 6.0 (following the recommended steps but keeping the .net core 5 hosting model) and I'm having a problem in dev: the initial load time of pages in the new version is very slow.
I have more or less pitpointed the issue to the use of Razor Runtime compilation:
IMvcBuilder mvcBuilder = services
.AddControllersWithViews(
configure =>
{
configure.InputFormatters.Insert(0, new RawJsonBodyInputFormatter()); // this allow receiving a JSON object as a string
configure.Filters.Add<PeppermintExceptionsFilter>(); //new UnauthorizedExceptionFilter());
})
.AddViewLocalization(Microsoft.AspNetCore.Mvc.Razor.LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization(option =>
{
option.DataAnnotationLocalizerProvider = (type, factory) => factory.Create(typeof(SharedResource));
})
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNamingPolicy = null;
})
.AddFluentValidation();
if (environment.IsDevelopment())
{
mvcBuilder.AddRazorRuntimeCompilation(); // commenting out this line resolves the issue
}
When the line is present, initial load for all pages takes up to 30 seconds (typically, the first page takes 30 seconds and other pages are often quicker).
If I comment out the option, then everything works fine again. This is clearly not a problem in production but it's really problematic (and frustrating) for developpement.
The problem is not present in asp.net core 5.0
Adding the AddRazorRuntimeCompilation option to a new .net 6.0 using the new hosting model) application seems to induce the same issue but I'm not sure because the compilation of pages in a nearly empty application is very quick.