Wednesday, December 3, 2014

ASP.Net: OData V4 Controller giving 406

What an obscure one...

If you have a seemingly complete controller and opening this url:

http://yoursite/api/Products

returns actual OData v4 results BUT this:

http://yoursite/api/Products(1)

returns a 404 error with:

No type was found that matches the controller named 'Products(1)'

then make sure your "using"s are adequate in your controller:

using System.Web.OData; <-- this should be used

vs

using System.Web.Http.OData;

By default, the WebAPI 2 ODataController template generates a class with the latter, and it gave me trouble.

2 comments:

Dillie-O said...

Thank you! I've spent half a day unwrapping and rewrapping this issue and came back to a simple library solution. Thank you for returning my sanity!

Jerther said...

I'm glad I could help!

Thing is, the 406 error can happen for so many different reasons...