Using "UseMvc" to configure MVC is not supported while using Endpoint Routing

🚀 Solving the "Using 'UseMvc' with Endpoint Routing" Issue in .NET Core 3.0
If you're working with an ASP.NET Core 2.2 project and recently upgraded to .NET Core 3.0 Preview 8, you might have come across a warning message that says:
"Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing. To continue using 'UseMvc', please set 'MvcOptions.EnableEndpointRouting = false' inside 'ConfigureServices'."
👉 The Problem:
You're now wondering what this warning means and how to solve it properly. Well, worry not. In this blog post, we'll explore the issue and discuss why Endpoint Routing doesn't need the traditional UseMvc() function. Plus, we'll provide you with the proper solution to overcome this problem. Let's dive in! 💪
The warning is triggered because ASP.NET Core 3.0 introduced a new routing system called Endpoint Routing, which provides a more integrated and flexible way to handle routing within the application. With Endpoint Routing, developers no longer need to use the UseMvc() function, as it is not required.
✅ The Solution:
Instead of using UseMvc(), you can simply use the UseEndpoints() method to configure your endpoints. Here's the proper way to solve this issue:
public void ConfigureServices(IServiceCollection services)
{
// Other service configurations
services.AddControllers(); // Add this line
services.Configure<MvcOptions>(options =>
{
options.EnableEndpointRouting = false; // Set Endpoint Routing to false
});
}
public void Configure(IApplicationBuilder app)
{
// Other app configurations
app.UseRouting(); // Add this line
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers(); // Add this line
});
}By adding services.AddControllers() in the ConfigureServices method and configuring MvcOptions to disable Endpoint Routing, you ensure that your MVC configuration is properly handled without using UseMvc().
💡 Why Does Endpoint Routing Not Need UseMvc()?
Endpoint Routing takes advantage of the new middleware pipeline introduced in ASP.NET Core 3.0. It integrates routing functionality directly into the pipeline, eliminating the need for additional configuration using UseMvc().
With Endpoint Routing, you can define routes directly on your controllers and actions using attributes like [Route]. This simplifies the configuration process and makes your code cleaner and more maintainable.
📣 Your Turn: Now that you know how to solve the "Using 'UseMvc' with Endpoint Routing" issue, go ahead and implement the solution in your project. If you have any questions or insights, feel free to share them in the comments below. Happy coding! 😊👩💻
Don't miss out on more exciting tech tips and guides! Subscribe to our newsletter for regular updates and follow us on Twitter for daily tech goodness. 💌🐦
Take Your Tech Career to the Next Level
Our application tracking tool helps you manage your job search effectively. Stay organized, track your progress, and land your dream tech job faster.



