Blog on software engineering
.NET 2.2 => NET 5.0 – Endpoint Routing does not support ‘IApplicationBuilder.UseMvc(…)

.NET 2.2 => NET 5.0 – Endpoint Routing does not support ‘IApplicationBuilder.UseMvc(…)

 

Solution

 

Use “endpoint” routing

Old

app.ConfigureExceptionHandler(loggerFactory);

app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseSpaStaticFiles();

app.UseAuthentication();

app.UseCors(“CorsPolicy”);

app.UseMvc(routes =>

{

routes.MapRoute(

name: “default”,

template: “{controller}/{action=Index}/{id?}”);

});

 

New

 

app.ConfigureExceptionHandler(loggerFactory);

app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseSpaStaticFiles();

app.UseRouting();

app.UseCors(“CorsPolicy”);

app.UseAuthentication();

app.UseEndpoints(endpoints => {

endpoints.MapControllerRoute(

name: “default”,

pattern: “{controller}/{action=Index}/{id?}”);

});

 

 

 

Error

System.InvalidOperationException

HResult=0x80131509

Message=Endpoint Routing does not support ‘IApplicationBuilder.UseMvc(…)’. To use ‘IApplicationBuilder.UseMvc’ set ‘MvcOptions.EnableEndpointRouting = false’ inside ‘ConfigureServices(…).

Source=Microsoft.AspNetCore.Mvc.Core

StackTrace:

at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvc(IApplicationBuilder app, Action`1 configureRoutes)

at BestandenDelen.Web.Startup.Configure(IApplicationBuilder app, IConfiguration configuration, IDatabaseService databaseService, IEnvironmentService environmentService, ILoggerFactory loggerFactory) in C:\Dev\bestanden-delen\BestandenDelen.Web\Startup.cs:line 157

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)

at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)

at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app)

at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)

at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)

at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)

at Microsoft.AspNetCore.Hosting.GenericWebHostService.<StartAsync>d__31.MoveNext()

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.