我用的也是2.2,出现异常!
System.InvalidOperationException
HResult=0x80131509
Message=Unable to find the required services. Please add all the required services by calling 'IServiceCollection.AddMvc' inside the call to 'ConfigureServices(...)' in the application startup code.
Source=Microsoft.AspNetCore.Mvc.Core
StackTrace:
at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.VerifyMvcIsRegistered(IApplicationBuilder app)
at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvc(IApplicationBuilder app, Action`1 configureRoutes)
at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvcWithDefaultRoute(IApplicationBuilder app)
at Lanzhoulamian.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in C:\Users\Administrator\Desktop\Lanzhoulamian\Lanzhoulamian\Startup.cs:line 27
?很强的学习能力!
通过查找百度找到问题了!
在ASP.NET Core 2.2中,新增了一种路由,叫做
Endpoint
(终结点)路由。本文将以往的路由系统称为传统路由
。本文通过源码的方式介绍传统路由和
Endpoint
路由部分核心功能和实现方法,具体功能上的差异见官方文档。在升级到ASP.NET Core 2.2后,会自动启用
Endpoint
路由public void ConfigureServices(IServiceCollection services)
{
//添加
services.AddMvc(options => options.EnableEndpointRouting = false)
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
services.AddMvc(options => options.EnableEndpointRouting = false),添加这条确实可以解决该问题,谢谢!