MVC, Troubleshooting

ASP.NET MVC fixing error ‘Multiple types were found that match the controller named’ when routing is not the problem

I just came across following error message while I was converting one of my ASP.NET MVC applications:

Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

The request for 'Home' has found the following matching controllers:
hbulens.WebUI.POC.Controllers.HomeController
hbulens.POC.WebUI.HomeController

Beschrijving: Er is een onverwerkte uitzondering opgetreden tijdens het uitvoeren van de huidige webaanvraag. Raadpleeg de stacktracering voor meer informatie over deze fout en de oorsprong ervan in de code.

Details van uitzondering: System.InvalidOperationException: Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

The request for 'Home' has found the following matching controllers:
hbulens.WebUI.POC.Controllers.HomeController
hbulens.POC.WebUI.HomeController

Normally, you would expect something is wrong with the routing engine, The error messages on this subject are quite clear:

[InvalidOperationException: Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

In my case, this wasn’t the problem. Instead, I changed the namespaces and assembly name of my MVC project from hbulens.WebUI.POC to hbulens.POC.WebUI, but the ASP.NET MVC project itself remained intact.

Being uncautious, I left the old assembly output in the bin folder while I was trying to debug the new assembly output, with beforementioned error as a result.

There is a very easy way to fix this: delete your bin folder and rebuild your project.

Advertisements
C#, Cloud, Entity Framework, MVC

Creating SQL schemas using Entity Framework Code First

As you might have read in my previous post, I used SQL schemas to partition data between tenants. Being part of the true definition of SaaS, a new tenant should be up and running within minutes without any human intervention.

With my suggested approach, we need to do two things:

  • Registering a new tenant
  • Attaching users to the tenant

In this article, I am going to focus on the first item whereas the second one shouldn’t be a big deal if you are planning to create software as a service.

Continue reading

Cloud, MVC

Multi-tenancy with ASP.NET MVC and Entity Framework

Until recently I have never had the time to concentrate on cloud application development. All of the projects (non-SharePoint related) I have ever worked on were dedicated to only one customer, so the multi tenancy challenge never came up. Although my own website is hosted on Azure, I realized I had to create my own project to gain some knowledge on this area.

There are many books and web pages available regarding cloud development, but for a very good reason none of those give really specific examples: it all depends on what you want to achieve. In this article, I will cover one scenario that is quickly to implement with the knowledge many .NET developers probably still have, which is developing a ASP.NET MVC application with Entity Framework which ensures storage in one database with multiple schemas. By giving some code excerpts, I hope to give you some rough ideas how to make your own multi-tenant applications.

Continue reading

MVC

Improve (perceived) performance in MVC 5 Applications: Part I

A couple of weeks ago, I launched my personal website hendrikbulens.com. It is a MVC5 application that is hosted on an Azure website with a SQL Azure database for the data storage.

Now that my website is up and running with real-live data, I am experiencing performance issues in different pages of the application.  To tackle this problem, there are a few enhancements that a developer can make. In this series, I will cover some techniques that are easy to implement that will improve the performance of a web site.

In this post, I will talk about asynchronous partial views.

Continue reading