Tuesday, May 27, 2014

Microsoft Web API: no type was found that matches the controller named..."

Symptom:

You have renamed a Web API 2 project, most likely borrowed some other sample code and now you want to modify it for your own purpose.

After you do this, and try to re-test the API to see if it still works, you get "no type was found that matches the controller named..."

You have renamed just about everything, including your default namespace in the entire project.

Root Cause:

It appears that there is some caching and old code is remaining in the project.

Fix that Worked for Me

In my situation, what ultimately worked was getting into the./bin directory of my Web API project and remove everything inside of it.

You also may want to move the Controller class files in the controller folder to another temporary location, then, have the Visual Studio create an empty skeleton controller class. Compile to make sure it builds. Then paste back the guts of the original logic. When you do this, you may go ahead and change the name of the class from the original to see that works.

You would think that Clean of the build would work, but I did try this and did not work for me until I manually deleted the bin contents.

If you are using the IIS Express server, then what you need to make sure is that it is completely killed off. In my case, I made sure of this by restarting the computer altogether.

At this time of writing, I am fairly new to this MVC stuff, so there are actual reasons why this broke in the first place. If you know really why, please be sure to share the knowledge with us.


Post a Comment