No overload for method 'UseRouting' takes 1 arguments

After some digging, I found a solution for this problem. Since dotnet core 3.0 requires some extra action, I will explain what I did to make this work. Firstable, in the ConfigureServices() method (in Startup.cs), remove:

services.AddMvc().AddNewtonsoftJson();

At the top of this method (under services.Configure<>), add the following lines:

    services.AddControllersWithViews()
        .AddNewtonsoftJson();
    services.AddRazorPages();

Next, in the Configure() method, add app.UseRouting() before app.UseAuthentication() and app.UseAuthorization(); and at the bottom of this method replace

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

with:

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

To quote the error message again:

EndpointRoutingMiddleware matches endpoints setup by EndpointMiddleware and so must be added to the request execution pipeline before EndpointMiddleware. Please add EndpointRoutingMiddleware by calling 'IApplicationBuilder.UseRouting' inside the call to 'Configure(...)' in the application startup code.

ASP.NET Core 3 uses a refined endpoint routing which will generally give more control about routing within the application. Endpoint routing works in two separate steps:

  • In a first step, the requested route is matched agains the configured routes to figure out what route is being accessed.
  • In a final step, the determined route is being evaluated and the respective middleware, e.g. MVC, is called.

These are two separate steps to allow other middlewares to act between those points. That allows those middlewares to utilize the information from endpoint routing, e.g. to handle authorization, without having to execute as part of the actual handler (e.g. MVC).

The two steps are set up by app.UseRouting() and app.UseEndpoints(). The former will register the middleware that runs the logic to determine the route. The latter will then execute that route.

If you read the error message carefully, between the somewhat confusing usage of EndpointRoutingMiddleware and EndpointMiddleware, it will tell you to add UseRouting() inside of the Configure method. So basically, you forgot to invoke the first step of endpoint routing.

So your Configure should (for example) look like this:

app.UseRouting();

app.UseAuthentication();

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

The routing migration to 3.0 is also documented in the migration guide for 3.0.