4

Let's have a SessionController in the main assembly of a Web API project:

public class SessionController : ApiController
{
   //...
}

So far so good, now I move parts of its functionality into a general class located in another assembly:

// AnotherAssembly.dll
public class SessionControllerBase : ApiController

// Main.dll
public class SessionController : SessionControllerBase

After that the API stops working with HTTP 404 - interestingly enough, not only for SessionController, but for all other controllers in the main library as well. I've verified that both assemblies are correctly loaded into the AppDomain, though.

{
   "Message": "No HTTP resource was found that matches the request URI 'http://localhost:1087/api/session'.",
   "MessageDetail": "No type was found that matches the controller named 'session'."
}

When I move the base class into the main library, there are no problems whatsoever.

What am I doing wrong?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
metalheart
  • 3,740
  • 1
  • 23
  • 29
  • 1
    The articles you posted are about controllers located in external assemblies. However, in my case the controller is located in the main assembly, only the base class is in an external one. – metalheart Sep 22 '14 at 13:45
  • Are you saying you have methods in the base controller that you expect to be routed to ? – pln Sep 22 '14 at 14:21
  • I tried this and had no issues. Try updating web api if you havent already. Also look at [this link](http://stackoverflow.com/questions/25102819/base-controller-from-another-class-library-doesnt-working-in-web-api?rq=1) and possibly [also this link](http://stackoverflow.com/questions/19989023/net-webapi-attribute-routing-and-inheritance) for inherited attribute routing. – pln Sep 22 '14 at 14:34
  • @pln yes, but I am using simple naming (SessionControllerBase.Post()) rather than attribute routing. which version of Microsoft.AspNet.WebApi.Core exactly are you using? – metalheart Sep 23 '14 at 05:09
  • It says web api 2.2 (5.2.2) – pln Sep 23 '14 at 08:00
  • 1
    I see, unfortunately, in the current project I am bound to .NET 4... – metalheart Sep 23 '14 at 08:13

0 Answers0