0

Recently i installed Fluent

I have two projects - one MVC and other Web Api project. Both have same controller named as Deals controller. After fluent installation, i got problem that web api request is not able to locate any DealsController.

In MVC's Gloabal asax- Application_Start method:

protected void Application_Start(object sender, EventArgs e)
{
            System.Web.Http.GlobalConfiguration.Configure(CompanyName.Service.WebApiConfig.Register);
            CompanyName.RouteConfig.RegisterRoutes(System.Web.Routing.RouteTable.Routes);

}

Both these statements registers the routes for mvc and web api respectively.

I have DealsController, which is located with the same name in both the projects (MVC and Web Api).

This is MVC's DealsController:

public class DealsController : System.Web.Mvc.Controller
{
    public DealsController()
    {

    }
}

This is Web Apis Deals controller:

public class DealsController : System.Web.Http.ApiController
{
    public DealsController()
        {

        }

    [Route("api/advantage/getDeals/")]
    public IHttpActionResult GetDeals([FromUri] CompanyName.Entity.Deals.Filters filter)
    {
    }
}

Post fluentvalidation.webapi installation from nuget, when i am hitting this web api's method: http://localhost/api/advantage/getDeals/?cityId=2&sc=0&so=1&pn=1

I am getting following error:

"Message": "No HTTP resource was found that matches the request URI 'http://localhost/api/advantage/getDeals/?cityId=2&sc=0&so=1&pn=1'.",

"MessageDetail": "No type was found that matches the controller named 'advantage'."

I dont know what exactly is happening post installation of fluent validation web api package. I just installed fluentvalidation.webapi package which gave me some cors related error, so i further installed Microsoft.AspNet.WebApi.Cors.

If i am renaming My web api controller (dealscontroller) to some other name, it is working fine.

But i don't understand what is exactly happening here and what other risk this update of fluentvalidation.webapi can have in my solution and other apis.

Sahil Sharma
  • 3,847
  • 6
  • 48
  • 98
  • When you have 2 separate projects why are you registering both MVC and WebAPI routes through MVC's Application_Start? There should be seperate application_start for each project. Am I missing something ? Also how are you calling your API ? – Ravi A. Aug 07 '16 at 10:01
  • Actually the project having Web apis is normal class library project. Its not actual Web api project. We manually add Web api controllers to this class library project. – Sahil Sharma Aug 07 '16 at 10:02

1 Answers1

1

I think when you are installing FluentValidation.WebAPI it is upgrading the Microsoft.AspNet.WebApi or other Web API libraries (although that shouldn't happen). If not this Microsoft.AspNet.WebApi.Cors will definitely change the version (if you are not on the latest version).

So you need to make sure the version of Web API libraries is same in both MVC project and class library.

Ravi A.
  • 2,163
  • 2
  • 18
  • 26
  • yeah.. i got some cors error for which i posted this. ( http://stackoverflow.com/questions/38803505/assembly-system-web-http-cors-5-2-3-0-uses-system-web-http-5-2-3-0-which-ha ) Please have a look at this post. May be you get some better insight into problem i am facing. – Sahil Sharma Aug 07 '16 at 16:30
  • although for this problem, i referred to (http://stackoverflow.com/questions/28604325/how-to-get-system-web-http-version-5-2-3-0) and installed web api core package which solved this build error issue. But later i found that this controller in solution (the duplicate one in mvc and web api) has stopped working. – Sahil Sharma Aug 07 '16 at 16:33
  • Sure I will look into your other post. But making the version same will fix this issue.Should be marked as answer . – Ravi A. Aug 07 '16 at 16:38
  • making which version same, i didnt get the solution. – Sahil Sharma Aug 07 '16 at 16:51
  • "So you need to make sure the version of Web API libraries is same in both Web API project and class library." what is class library here? – Sahil Sharma Aug 07 '16 at 16:52
  • All the Web API libraries like Microsoft.AspNet.WebApi , Microsoft.AspNet.WebApi.Client, Microsoft.AspNet.WebApi.Core etc. between your MVC project and the other Class library project that has Web API Controller . Edited my answer – Ravi A. Aug 07 '16 at 17:03
  • i need to check all the versions of web api in all my projects. i would check it tomorrow as i do not have access to that code right now. Once verified, i will accept the answer. thanks for your help. – Sahil Sharma Aug 07 '16 at 17:14
  • as far as i understood is that i should install latest version ofMicrosoft.AspNet.WebApi , Microsoft.AspNet.WebApi.Client, Microsoft.AspNet.WebApi.Core etc. in both my MVC and Web Api project. Please correct me if i am wrong. – Sahil Sharma Aug 07 '16 at 17:18
  • No not necessary, although there is no harm in doing that. However the version should be same in both the projects for your situation. Hint - Check version mismatches in packages.config. – Ravi A. Aug 07 '16 at 17:21
  • Cool. I will check that. – Sahil Sharma Aug 07 '16 at 17:22
  • Hi, i am trying. But don't know how to proceed. I am sharing my packages.config file pre and post fluentvalidation.webapi installation. https://jpst.it/LU1u Please let me know what should i do next? – Sahil Sharma Aug 08 '16 at 06:12
  • Go to Tools -> Nuget Package Manager ->Package Manager Console. Change Default Project to your MVC project Run Update-Package Microsoft.AspNet.WebApi -version 5.1.0 – Ravi A. Aug 08 '16 at 14:00