一个 ASP.NET Core 2.1 的站点,日志中有大量下面的错误:
System.InvalidOperationException: No service for type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor' has been registered.
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
请问如何解决?
引发这个问题的代码:
var services = HttpContext.RequestServices;
var executor = services.GetRequiredService<ViewResultExecutor>();
var viewEngine = services.GetRequiredService<IRazorViewEngine>();
services.AddRazorPages();