I was upgrading project frmework from ASP.NET Core 2.1 to ASP.NET Core 3.1 and I got below exception error in my Startup.cs class.

Error details :

“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 ProjectName.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in ProjectDirectoryPath\Startup.cs:line 89 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.ConventionBasedStartup.Configure(IApplicationBuilder app)”

When I continue to run the project, Page loaded with below error message.

Solution:

Inside Configuration() method of Startup.cs file, we need to change below code

app.UseMvc(routes =>
            {
           routes.MapRoute(
          name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
            });

To

app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });

Thing is after migration to ASP.NET Core 3.1, we have to use UseEndPoints() instead of UseMVC();

Hope, this helps you resolve your issue after upgrading your project from ASP.NET Core 2.1 to ASP.NET Core 3.1.

Leave a Reply

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